#include using namespace std; #define FOR(i,a,b) for(auto i=a;i; using vvi=vector; using pii=pair; #define MX 5007 ll n; ll v[MX]; ll DP[MX][MX]; ll dp(ll a, ll b) { if(a>=b) return 0; ll &ret=DP[a][b]; if(~ret)return ret; ret=0; if(v[a]==v[b]) ret=1+dp(a+1,b-1); ret=max(ret,dp(a+1,b)); ret=max(ret,dp(a,b-1)); return ret; } int main(){ ios::sync_with_stdio(false);cout.tie(0);cin.tie(0); for(;;) { cin>>n; if(!cin)break; F(n) cin>>v[i]; memset(DP,-1,sizeof(DP)); cout << dp(0,n-1) <