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

#GL0000160. Đoạn con có GCD nguyên tố (Prime Dominion)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đoạn con có GCD nguyên tố (Prime Dominion)

Prime Dominion

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positive-integer array a1,…,ana_1,\ldots,a_n, a contiguous subarray [l,r][l,r] is valid if its GCD is a prime number. Determine the maximum length of a valid subarray. Single-element subarrays are allowed. Print -1 when no valid subarray exists.

Input

The first line contains nn. The next line contains the nn array values.

Output

Print the length of the longest valid subarray, or -1 if none exists.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301 \le n \le 30; 1≤ai≤5001 \le a_i \le 500.
  • Subtask 2 (30 points): 1≤n≤50001 \le n \le 5000; 1≤ai≤2⋅1041 \le a_i \le 2\cdot10^4.
  • Subtask 3 (50 points): 1≤n≤2⋅1051 \le n \le 2\cdot10^5; 1≤ai≤2⋅1051 \le a_i \le 2\cdot10^5.

Examples

Input

5
2 4 6 9 3

Output

3

Explanation

The contiguous subarray [6,9,3][6,9,3] at positions 33 through 55 has GCD 33, a prime, and has length 33. No longer subarray has prime GCD.