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

#GL0000119. Cặp chỉ số nguyên tố cùng nhau (Coprime)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Cặp chỉ số nguyên tố cùng nhau (Coprime)

Coprime

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn positive integers a1,…,ana_1,\ldots,a_n, indexed from 11, maximize i+ji+j over all indices 1≤i,j≤n1\le i,j\le n satisfying gcd⁡(ai,aj)=1\gcd(a_i,a_j)=1. The two indices may coincide. Print -1 if no such pair exists.

Input

The first line contains nn. The second contains nn integers aia_i.

Output

Print the maximum i+ji+j, or -1 if no valid pair exists.

Subtasks

  • Subtask 1 (20 points): 2≤n≤602\le n\le 60; 1≤ai≤501\le a_i\le 50.
  • Subtask 2 (30 points): 2≤n≤10 0002\le n\le 10\,000; 1≤ai≤5001\le a_i\le 500.
  • Subtask 3 (50 points): 2≤n≤200 0002\le n\le 200\,000; 1≤ai≤1 0001\le a_i\le 1\,000.

Examples

Input

3
3 2 1

Output

6

Explanation

Choose i=j=3i=j=3: since a3=1a_3=1 and gcd⁡(1,1)=1\gcd(1,1)=1, the sum of indices is 66. Equal indices are allowed.