Relatively prime tower
Koi has a lot of cube blocks, today he wants to build a tower that is both "sturdy" and "good-looking" by stacking them on top of each other.
For the tower to be "sturdy"
each of its block must have a volume more than the one above. For the tower to be "good-looking", the volumes of two
consecutive blocks must be relatively
prime, i.e their greatest common
divisor is
The height of the tower is calculated as the sum of its block's edges.
Given a sequence of positive integers that are the edge length of Koi's blocks, your task is to determine the height of the highest tower satisfy Koi's conditions.
Input
The first line contains an integer
The second line contains
Output
A single integer - the height of the highest tower Koi wants to build.
Subtask
Example
Input 1:
5
3 6 5 3 1
Output 1:
15
Explaination: Koi can use two blocks
Input 2:
4
2 3 6 9
Output 2:
11
Explaination: Koi can use three blocks
Comments