#JSUTFPC2025K. Rabbit Sequence —— 兔子序列

Rabbit Sequence —— 兔子序列

Statement

The rabbit sequence, also known as the Fibonacci sequence, is a sequence of length nn denoted as {an}\left\{ a_n \right\} if and only if it satisfies one of the following conditions:

  1. n=1n=1 or n=2n=2;
  2. When n3n\geqslant 3,  i[3,n]\forall ~ i\in [3,n] satisfies ai2+ai1=aia_{i-2}+a_{i-1}=a_i.

Given an array aa consisting of positive integers, find the length of the longest consecutive rabbit subsequence of the array aa [1].

Input

The first line contains an integer nn representing the length of the sequence; where nn satisfies 1n1×1051\leqslant n\leqslant 1\times 10^5

The second line contains nn integers aia_i representing the number of occurrences of each number in the array; each number satisfies 1ai1×1091 \leqslant a_i \leqslant 1 \times 10^9.

Output

Output an integer representing the length of the longest consecutive rabbit subsequence of {an}\left\{ a_n \right\}.

Samples

8
1 1 1 1 2 3 5 1
5
5
5 2 7 9 16
5

Notes

对于第一组样例最长的连续兔子子序列是 [1,1,2,3,5][1, 1, 2, 3, 5],长度为 5。

对于第二组样例最长的连续兔子子序列是 [5,2,7,9,16][5, 2, 7, 9, 16],长度为 5。


  1. A sequence s1s_1 is a consecutive rabbit subsequence of another sequence s2s_2 if and only if there exists an interval [,r][\ell, r] such that s1s_1 is exactly equal to a subsequence of s2s_2 within that interval and s1s_1 is a rabbit sequence. ↩︎