#K86137. Longest Arithmetic Progression

    ID: 36798 Type: Default 1000ms 256MiB

Longest Arithmetic Progression

Longest Arithmetic Progression

Given a sequence of integers, your task is to determine the length of the longest arithmetic progression (AP) that can be formed from the sequence. An arithmetic progression is a sequence where the difference between consecutive elements is constant, i.e. an AP follows the formula: $$a,; a+d,; a+2d,; \dots$$ where (d) is the common difference. The input does not guarantee that the numbers are sorted. You must account for this and compute the longest AP length accordingly.

inputFormat

The first line of input contains a single integer (n), representing the number of elements in the sequence. The second line contains (n) space-separated integers.

outputFormat

Output a single integer which is the length of the longest arithmetic progression in the given sequence.## sample

6
1 7 10 13 14 19
4