GCD Sum

For each k from 1 to n, split a multiset of n numbers into k nonempty groups to maximize the sum of the groups' gcds. n is up to 500000 and each value up to 10^12.

Hard9Number theoryGreedyMathSortingNo attempts yetTime limit2sMemory limit1024 MB

Problem

You are given a multiset of nn integers, so the same value can appear several times. Split the multiset into kk nonempty groups, where every element belongs to exactly one group. For each group compute the greatest common divisor of its elements, then add those divisors together.

For every k=1,2,,nk = 1, 2, \ldots, n, find the largest sum you can obtain this way.

Input

The first line contains the size of the multiset nn (1n5000001 \leq n \leq 500\,000).

The second line contains the nn positive integers of the sequence. Each integer is at most 101210^{12}.

Output

Print nn lines. Line ii contains the largest sum of greatest common divisors over all splits of the multiset into k=ik = i groups.

Hint

For the sequence 10,9,10,310, 9, 10, 3 and k=2k = 2, the best split is (10,10)(10, 10) and (9,3)(9, 3), with sum 10+3=1310 + 3 = 13. For k=3k = 3 the best split is (10)(10), (10)(10), (9,3)(9, 3), with sum 2323.