Fibonacci sequence
Medium
Execution time limit is 4 seconds
Runtime memory usage limit is 256 megabytes
A set of distinct integers is given. Find the length of the longest sequence of Fibonacci numbers that can be arranged from them. Each number can be used in the sequence no more than once. The sequence F is called the Fibonacci sequence, if
F[1]
= a
F[2]
= b
F[i]
= F[i–2]
+ F[i–1]
Input
The first line contains the number n (2 ≤ n ≤ 10000) of elements in the set. The second line contains n distinct integers a[i]
(1 ≤ a[i]
≤ 10^9
).
Output
Print the length of the longest Fibonacci sequence, that can be created from given numbers.
Examples
Input #1
Answer #1
Submissions 730
Acceptance rate 7%