PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000384. Mảng và ước chung lớn nhất (Array and GCD)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mảng và ước chung lớn nhất (Array and GCD)

Array and GCD

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn integers, each at least 22, and initially have zero coins. You may repeatedly perform either operation on the remaining array:

  • Increase one element by 11, paying one coin (only if you have enough coins).
  • Decrease one element by 11, gaining one coin.

An array is ideal if every element is at least 22 and every pair of elements at distinct positions has GCD 11. For arrays of fewer than two elements, the pairwise condition holds automatically.

An array is beautiful if it can be transformed into an ideal array using these operations, starting from zero coins and never spending coins you do not have.

You may remove any number of elements beforehand, including all of them. Find the minimum number of removals making the remaining array beautiful.

PHOJ input convention: Each .in file contains one test case with no leading tt.

Input

The first line contains nn, and the second line contains a1,…,ana_1,\ldots,a_n.

Output

Print the minimum number of elements to remove.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12, 2≤ai≤1092\le a_i\le10^9.

  • Subtask 2 (30 points): 1≤n≤10 0001\le n\le10\,000, 2≤ai≤1092\le a_i\le10^9.

  • Subtask 3 (50 points): 1≤n≤400 0001\le n\le400\,000, 2≤ai≤1092\le a_i\le10^9.

Examples

Example 1

Input

3
5 5 5

Output

0

Explanation

Reduce the first 55 to 44, then another 55 to 33, obtaining [4,3,5][4,3,5]. All pairs are coprime, and decreasing costs no coins. Thus no removal is needed.

Example 2

Input

4
2 3 2 4

Output

2

Explanation

Keeping [2,3][2,3] yields an ideal array, so two removals suffice. Keeping any three elements gives a total of at most 4+3+2=94+3+2=9, while the smallest possible sum of three pairwise coprime integers at least 22 is 2+3+5=102+3+5=10. Starting with zero coins, operations cannot increase the total sum, so three elements cannot be kept.