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

#SP0000220. Dãy tốt dài nhất (Good Sequences)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Dãy tốt dài nhất (Good Sequences)

Good Sequences

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Squirrel Liss has nn distinct positive integers in strictly increasing order, a1<a2<⋯<ana_1<a_2<\cdots<a_n. You may select a subsequence, skipping some values but keeping the order.

The selected sequence is good if the greatest common divisor of every adjacent pair is greater than 11. A single-element sequence is valid because it contains no adjacent pair. Find the maximum possible length of a good sequence.

Input

The first line contains nn. The second line contains the nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in strictly increasing order.

Output

Print a single integer: the maximum length of a subsequence whose every adjacent pair has greatest common divisor greater than 11.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20; 1≤a1<a2<⋯<an≤1051\le a_1<a_2<\cdots<a_n\le10^5.

  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤a1<a2<⋯<an≤1051\le a_1<a_2<\cdots<a_n\le10^5.

  • Subtask 3 (50 points): 1≤n≤1051\le n\le10^5; 1≤a1<a2<⋯<an≤1051\le a_1<a_2<\cdots<a_n\le10^5.

Examples

Input

5
2 3 4 6 9

Output

4

Explanation

Choose 2,4,6,92,4,6,9, a sequence of length 44. Its adjacent gcd values are gcd⁡(2,4)=2\gcd(2,4)=2, gcd⁡(4,6)=2\gcd(4,6)=2, and gcd⁡(6,9)=3\gcd(6,9)=3, all greater than 11. A length-55 subsequence would have to contain every input element, but its first adjacent pair 2,32,3 has gcd 11. Therefore no length-55 good subsequence exists and the maximum length is 44.