#include<iostream>
#include<utility>
#include<queue>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
typedef pair<int,int> pii;
long long dp[2010][2010]={0},in[2020],n,o;
queue<pii>q;
int main(){
	cin>>n;rep(i,n)cin>>in[i];
	rep(i,n)dp[i][1]=in[i],q.push(pii(i,1));
	while(!q.empty()){
		pii r=q.front();q.pop();
		int a=r.first,b=r.second,s=a-1,t=(s+1+b)%n;
		if(s==-1)s=n-1;
		rep(i,2){
			if(b%2&&in[s]<in[t])s=a;
			int w=b%2?0:in[(i?t:s)];
			if(dp[s][++b]<dp[a][b-1]+w){
				dp[s][b]=dp[a][b-1]+w;
				if(b!=n)q.push(pii(s,b));
			}
			if(--b%2==0)s=a;
		}
	}
	rep(i,n)o=max(o,dp[i][n]);
	cout<<o<<endl;
}