LogiQuest

260. Longest Arithmetic Subsequence

MediumDynamic ProgrammingHash Map

Print the length of the longest subsequence whose consecutive differences are all equal.

Input format

Line 1: n Line 2: n integers

Output format

The length.

Example 1

Input

4
3 6 9 12

Output

4

Example 2

Input

5
9 4 7 2 10

Output

3

Constraints

2 ≤ n ≤ 1000

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…