PivotOJ

Gingerbread

시간 제한: 2000ms메모리 제한: 2048MB출처: BOI 2025BOJ 33859

문제

Toruń has been known for its traditional gingerbread since the Middle Ages. Young Nicolaus would like to buy a set of nn boxes with gingerbread cookies in his favourite shop. The shop has very strict rules, though: Nicolaus initially obtains n boxes that are already filled with cookies: the ii-th box initially contains aia_i of them. Then, Nicolaus can order some extra cookies. He adds extra cookies to some boxes so that the greatest common divisor^∗ of the numbers of cookies in all of the boxes becomes equal to 11. It can be proven that this is always possible.

Help Nicolaus by calculating the smallest number of cookies that need to be added in order to make the greatest common divisor of all the numbers equal to 11.


^∗The greatest common divisor (GCD) of multiple numbers is the largest positive integer that divides all of them without remainder.

입력

The first line contains an integer nn (2 ≤ n ≤ 10^6), denoting the number of boxes.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots , a_n (1 ≤ a_i ≤ 10^7), where the ii-th integer aia_i denotes the initial number of cookies in the ii-th box.

출력

Output one line with a single integer denoting the smallest number of cookies that Nicolaus should add to the boxes. If Nicolaus doesn’t have to add any cookies to make the greatest common divisor of the numbers equal to 11, output 00.

힌트

Explanation of the example: Indeed, the greatest common divisor (GCD) of 9090, 8484, and 140140 is 22, so some cookies must be added. If we add only one cookie, we may obtain the quantities 9191, 8484, 140140 with GCD of 77, or 9090, 8585, 140140 with GCD of 55, or 9090, 8484, 141141 with GCD of 33, so this is not enough. After adding two cookies, one to the first box, and one to the second box, we obtain the quantities 9191, 8585, 140140 with GCD of 11; hence the answer is 22. Note that adding both cookies to the first box does not help: we obtain quantities 9292, 8484, 140140 with GCD of 44.

예제

예제 1

입력
3
90 84 140
출력
2
코드를 제출하려면 로그인하세요.