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

#SP0000228. Món quà của Chef (Cute Chef Gift)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Món quà của Chef (Cute Chef Gift)

Cute Chef Gift

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

Chef has a sequence of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. He wants to split it after position ll. Let PP be the product of a1,…,ala_1,\ldots,a_l and QQ the product of al+1,…,ana_{l+1},\ldots,a_n. The empty suffix when l=nl=n has product 11.

A split is valid if gcd⁡(P,Q)=1\gcd(P,Q)=1: no prime divides both products. Find the smallest valid index ll. The products can be enormous and need not be calculated explicitly.

Input

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

Output

Print the smallest split index ll such that 1≤l≤n1\le l\le n and gcd⁡(P,Q)=1\gcd(P,Q)=1.

Subtasks

  • Subtask 1 (20 points): 1≤n≤121\le n\le12; 1≤ai≤1051\le a_i\le10^5 for every ii.

  • Subtask 2 (30 points): 1≤n≤50001\le n\le5000; 1≤ai≤1051\le a_i\le10^5 for every ii.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤ai≤1051\le a_i\le10^5 for every ii.

Examples

Input

4
2 3 4 5

Output

3

Explanation

For the array (2,3,4,5)(2,3,4,5), cutting at l=1l=1 gives products 22 and 6060, with gcd 22. At l=2l=2 the products are 66 and 2020, again sharing factor 22. At l=3l=3 the products are 2424 and 55, and gcd⁡(24,5)=1\gcd(24,5)=1. Thus the first valid split is 33.