#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll dp[2000][2000];
ll d,a[2000];
ll rec(ll x,ll y){//x~y?????¨??£???
	if(dp[x][y]!=-1) return dp[x][y];
	if((y+1)%d==x) return dp[x][y]=0;
	if((y+2)%d==x) return dp[x][y]=a[(y+1)%d];
	ll res=0;
	//x-1?????????
	if(a[(x-2+d)%d]<a[(y+1)%d]){
		res=max(res,a[(x-1+d)%d]+rec((x-1+d)%d,(y+1)%d));
	}
	else{
		res=max(res,a[(x-1+d)%d]+rec((x-2+d)%d,y));
	}
	//y+1?????????
	if(a[(x-1+d)%d]<a[(y+2)%d]){
		res=max(res,a[(y+1)%d]+rec(x,(y+2)%d));
	}
	else{
		res=max(res,a[(y+1)%d]+rec((x-1+d)%d,(y+1)%d));
	}
	return dp[x][y]=res;
}
ll ans=0;
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>d;
	rep(i,d) cin>>a[i];
	rep(i,d){
		if(a[(i+1)%d]>a[(i-1+d)%d]){
			ans=max(ans,a[i]+rec(i,(i+1)%d));
		}
		else{
			ans=max(ans,a[i]+rec((i-1+d)%d,i));
		}
	}
	cout<<ans<<endl;
}