#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
ll dp[2010][2010]={0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	queue<pip>q;
	rep(i,n){
		dp[i][1]=in[i];
		q.push(pip(1,pii(i,1)));
	}
	while(!q.empty()){
		pip a=q.front();
		pii b=a.second;
//		cout<<a.first<<" "<<b.first<<" "<<b.second<<" "<<dp[b.first][b.second]<<endl;
		q.pop();
		int s=b.first;
		int t=b.first+b.second;
		if(t>=n)t-=n;
		s--;
		if(s==-1)s=n-1;
		if(t==n)t=0;
//		cout<<s<<" "<<t<<endl;
		if(a.first){//IOI
			if(in[s]>in[t]){
				if(dp[s][b.second+1]<dp[b.first][b.second]){
					dp[s][b.second+1]=dp[b.first][b.second];
					if(b.second+1!=n)q.push(pip(0,pii(s,b.second+1)));
				}
			}else{
				if(dp[b.first][b.second+1]<dp[b.first][b.second]){
					dp[b.first][b.second+1]=dp[b.first][b.second];
					if(b.second+1!=n)q.push(pip(0,pii(b.first,b.second+1)));
				}
			}
		}else{//JOI
			if(dp[s][b.second+1]<dp[b.first][b.second]+in[s]){
				dp[s][b.second+1]=dp[b.first][b.second]+in[s];
				if(b.second+1!=n)q.push(pip(1,pii(s,b.second+1)));
			}
			if(dp[b.first][b.second+1]<dp[b.first][b.second]+in[t]){
				dp[b.first][b.second+1]=dp[b.first][b.second]+in[t];
				if(b.second+1!=n)q.push(pip(1,pii(b.first,b.second+1)));
			}
		}
	}
	ll out=0;
	rep(i,n)out=max(out,dp[i][n]);
	cout<<out<<endl;
}