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

#GL0000143. Đưa ƯCLN về một (Make It One)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đưa ƯCLN về một (Make It One)

Make It One

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. Select a nonempty subset of distinct indices; the chosen positions need not be consecutive and each index is used at most once.

The score of the subset is the GCD of its values. Find the minimum subset size with score equal to 11, or print -1 if no such subset exists. Equal values at different indices are still distinct elements.

Input

The first line contains nn; the second contains nn positive integers aia_i.

Output

Print the minimum number of elements in a subset with GCD 11, or -1 if none exists.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le 12; 1≤ai≤601\le a_i\le 60.
  • Subtask 2 (30 points): 1≤n≤5 0001\le n\le 5\,000; 1≤ai≤5 0001\le a_i\le 5\,000.
  • Subtask 3 (50 points): 1≤n≤300 0001\le n\le 300\,000; 1≤ai≤300 0001\le a_i\le 300\,000.

Examples

Input

3
10 6 15

Output

3

Explanation

The GCD of all three values 10,6,1510,6,15 is 11, while pairwise GCDs are 22, 55, and 33. No one- or two-element subset works, so all three elements are needed.