problems / 241

Suki's Identical Treat Bundles

easy gcd math number-theory arrays 1000 ms · 256 MB

Suki's Identical Treat Bundles

Suki, a black curly-coated dog with a grey beard and white paws, has hidden treats of n different kinds all around the garden: c_i treats of kind i. Before her walks she wants to dig them all up and pack them into bundles, one bundle per walk, and she wants as many walks as possible.

Every bundle must be identical: each one holds the same number of treats of kind 1, the same number of kind 2, and so on. Every treat must go into some bundle, so none is left over.

Find the largest possible number of bundles, and how many treats of each kind go into one bundle.

Input

The first line contains n (1 ≤ n ≤ 10^5), the number of kinds of treats.

The second line contains n integers c_1, c_2, …, c_n (1 ≤ c_i ≤ 10^12), the number of treats of each kind.

Output

On the first line print k, the largest number of bundles.

On the second line print n integers: the number of treats of kind 1, kind 2, …, kind n in one bundle.

Notes

In the first example, Suki has 12, 18 and 30 treats. She can make 6 bundles of 2, 3 and 5 treats. She can't make more: 7, 8, 9, 10, 11 and 12 bundles all fail to split 12 or 18 evenly, and there can't be more bundles than she has treats of kind 1.

In the second example, 7 and 10 share no common divisor other than 1, so all the treats go into a single bundle.

In the third example, Suki has only one kind of treat, so each of the 10^12 treats becomes its own bundle. Counts and the number of bundles can exceed 2^31: use a 64-bit integer type.

Example 1

Input

3
12 18 30

Output

6
2 3 5

Example 2

Input

2
7 10

Output

1
7 10

Example 3

Input

1
1000000000000

Output

1000000000000
1

Hints · reveal one at a time if you're stuck

Hint 1

If Suki makes k bundles and each holds b_i treats of kind i, how are k, b_i and c_i related?

Hint 2

The number of bundles must divide every count c_i, and any number that divides them all works. So you want the greatest common divisor of all the counts.

report an issue Prefer your own editor? sooks prep 241 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.