You are given an array of size N. Rearrange it in such a manner that the sum of the GCD over all the non-empty prefixes of the array is maximum.
GCD here means greatest common divisior. It is the largest number which divides any set of numbers without leaving any remainder with any of them.
Input format:
Output format:
Print the answer — the maximum possible sum of all the prefix GCD's of the rearranged array.
Constraints:
1≤N≤201≤Ai≤109
Here we can rearrange the array as 12 6 8. This arrangemment the sum of the GCD of the prefix will be gcd(12)+gcd(12,6)+gcd(12,6,8). This would have the maximum possible sum of 20.