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

#SP0000245. Bài toán số học thực sự của Ehab (Ehab’s REAL Number Theory Problem)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bài toán số học thực sự của Ehab (Ehab’s REAL Number Theory Problem)

Ehab's REAL Number Theory Problem

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array aa of nn positive integers. Each aia_i has at most seven positive divisors, including 11 and itself.

Choose a non-empty subsequence whose product is a perfect square, minimizing the number of chosen elements. Elements may be skipped, but each input position may be selected at most once. A perfect square is an integer of the form t2t^2 with integral tt. Output the smallest subsequence length, or -1 if none exists. You do not need to print the subsequence itself.

Input

The first line contains nn. The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the minimum positive number of selected elements whose product is a perfect square, or -1 if impossible.

Subtasks

  • Subtask 1 (20 points): 1≤n≤141\le n\le14; 1≤ai≤1001\le a_i\le100 for all ii; each aia_i has at most seven positive divisors.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le1000; 1≤ai≤1041\le a_i\le10^4 for all ii; each aia_i has at most seven positive divisors.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤ai≤1061\le a_i\le10^6 for all ii; each aia_i has at most seven positive divisors.

Examples

Input

3
6 15 10

Output

3

Explanation

For [6,15,10][6,15,10], none of the individual entries is a square. No pair gives a square: 6⋅15=906\cdot15=90, 6⋅10=606\cdot10=60, and 15⋅10=15015\cdot10=150. Selecting all three yields 6⋅15⋅10=900=3026\cdot15\cdot10=900=30^2. Thus the shortest valid non-empty subsequence has length 33, so print 3.