Codeforces Round 156 (Div. 2)
C
Almost Arithmetical Progression
Codeforces
1500
原题
← BD →
翻译中…

Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:

翻译中…
  • $*a*_{1} = *p*$, where $*p*$ is some integer;
  • $*a*_{*i*} = *a*_{*i* - 1} + ( - 1)^{*i* + 1}·*q*$ $(*i* > 1)$, where $*q*$ is some integer.
翻译中…

Right now Gena has a piece of paper with sequence $*b*$, consisting of $*n*$ integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.

翻译中…

Sequence $*s*_{1},  *s*_{2},  ...,  *s*_{*k*}$ is a subsequence of sequence $*b*_{1},  *b*_{2},  ...,  *b*_{*n*}$, if there is such increasing sequence of indexes $*i*_{1}, *i*_{2}, ..., *i*_{*k*}$ $(1  ≤  *i*_{1}  <  *i*_{2}  < ...   <  *i*_{*k*}  ≤  *n*)$, that $*b*_{*i*_{*j*}}  =  *s*_{*j*}$. In other words, sequence $*s*$ can be obtained from $*b*$ by crossing out some elements.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ $(1 ≤ *n* ≤ 4000)$. The next line contains $*n*$ integers $*b*_{1}, *b*_{2}, ..., *b*_{*n*}$ $(1 ≤ *b*_{*i*} ≤ 10^{6})$.

翻译中…

Output

翻译中…

Print a single integer — the length of the required longest subsequence.

翻译中…

Note

翻译中…

In the first test the sequence actually is the suitable subsequence.

翻译中…

In the second test the following subsequence fits: $10, 20, 10$.

翻译中…

样例

Input #1
2
3 5
Output #1
2
InputCopy OutputCopy
Input #2
4
10 20 10 30
Output #2
3
InputCopy OutputCopy
题目信息
题号
255C
时间限制
1 s
内存限制
256 MB
标签
暴力
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。