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

#SP0000224. Kirito vượt mê cung (Kirito in labyrinth)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Kirito vượt mê cung (Kirito in labyrinth)

Kirito in labyrinth

Source: CodeChef

Version: Phuoc Hung OJ Extended

Problem Statement

Kirito travels through a tunnel with nn rooms numbered 11 to nn. Room ii contains aia_i monsters. He moves forward only and, at each room, may clear its monsters or skip the room.

A curse applies to every two consecutively chosen rooms: if their monster counts are xx and yy, then gcd⁡(x,y)>1\gcd(x,y)>1 must hold. Skipped rooms do not influence the condition.

Find the maximum number of rooms Kirito can clear without breaking the curse. Values may repeat. A room containing one monster can only be the sole chosen room.

Input

The first line contains nn. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n giving the monster counts in the rooms.

Output

Print the maximum number of rooms that can be chosen in increasing index order, with gcd greater than 11 for every two consecutively chosen rooms.

Subtasks

  • Subtask 1 (30 points): 1≤n≤1031\le n\le10^3; 1≤ai≤1071\le a_i\le10^7 for every ii.

  • Subtask 2 (70 points): 1≤n≤1051\le n\le10^5; 1≤ai≤1071\le a_i\le10^7 for every ii.

Examples

Input

7
13 2 8 6 3 1 9

Output

5

Explanation

Choose rooms 2,3,4,5,72,3,4,5,7, with monster counts 2,8,6,3,92,8,6,3,9. The adjacent gcd values are 2,2,3,32,2,3,3, all strictly greater than 11, so 55 rooms can be cleared. Room 11 with value 1313 is coprime to all later room values, while room 66 with value 11 cannot be adjacent to any other selected room. Thus no sequence of 66 rooms exists, and the maximum is 55.