Longest Arithmetic Progression

No attempts yetTime limit2sMemory limit1024 MB

Problem

An arithmetic progression is an ascending sequence a1<a2<<ana_1 < a_2 < \dots < a_n in which the difference between two consecutive elements is always the same. For example, 11<21<31<41<5111 < 21 < 31 < 41 < 51 is an arithmetic progression.

A subsequence of an ascending sequence aa of nn numbers is an ascending sequence b1<b2<<bmb_1 < b_2 < \dots < b_m with mnm \le n whose elements all occur in aa. For example, 21<41<5121 < 41 < 51, 11<4111 < 41, and 11<21<31<41<5111 < 21 < 31 < 41 < 51 are subsequences of 11<21<31<41<5111 < 21 < 31 < 41 < 51.

You are given an ascending sequence c1<c2<<ckc_1 < c_2 < \dots < c_k. Find the length of a longest arithmetic progression that is a subsequence of cc. There may be several longest arithmetic progressions, but the length is unique.

A sequence of one element or two elements also satisfies the definition, so the answer is never smaller than 2.

kk is at least 10 and at most 500, and every element of cc is a positive integer smaller than 100000.

Input

The input has two lines. The first line contains the number of elements kk of cc. The second line contains the elements of cc in ascending order, separated by spaces.

Output

Print, on one line, the length of the longest arithmetic progression that is a subsequence of cc.