#K82867. Longest Fibonacci-like Subsequence
Longest Fibonacci-like Subsequence
Longest Fibonacci-like Subsequence
You are given a list of integers. Your task is to find the length of the longest subsequence that forms a Fibonacci-like sequence.
A sequence X[ i ], X[ j ], X[ k ] (with i < j < k) is considered Fibonacci-like if it satisfies the relation:
\(X[i] + X[j] = X[k]\)
If no such subsequence of length at least 3 exists, output 0.
Note: The subsequence does not need to be contiguous. Input numbers are given in the order they appear in the sequence.
inputFormat
The first line contains a single integer N
(the number of elements in the sequence). The second line contains N
space-separated integers.
outputFormat
Output a single integer: the length of the longest Fibonacci-like subsequence. If none exists with length at least 3, output 0.
## sample0
0