发现规律序列为a,b,a,b,a,b即可.
#include<bits/stdc++.h>
using namespace std;#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
const int mod=1e9+7;
const int maxn=4e3+10;
const int ub=1e6;
ll powmod(ll x,ll y){ll t; for(t=1;y;y>>=1,x=x*x%mod) if(y&1) t=t*x%mod; return t;}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
int n,a[maxn],b[maxn],ans;
int dp[maxn][maxn],pos[maxn];
map<int,int> mp;
int main(){ios::sync_with_stdio(false);cin>>n;rep(i,0,n) cin>>a[i],b[i]=a[i],ans=max(ans,++mp[a[i]]);sort(b,b+n);int cnt=unique(b,b+n)-b;rep(i,0,n) pos[i]=lower_bound(b,b+cnt,a[i])-b;rep(i,0,n) rep(j,0,n) dp[pos[i]][pos[j]]=1;rep(i,0,n) rep(j,0,i) {if(pos[i]==pos[j]) continue;dp[pos[i]][pos[j]]=max(dp[pos[i]][pos[j]],dp[pos[j]][pos[i]]+1);ans=max(ans,dp[pos[i]][pos[j]]);}cout<<ans;return 0;
}