#include<iostream>
using namespace std;

long long int a[4001];
long long int dp[4001][4001];

long long int dfs(int x,int y){
	if(y<x){
		return 0;
	}else{
		if(dp[x][y]<0){
			if(a[x]>a[y-1]){
				if(a[x+1]>a[y]){
					dp[x][y]=max(a[x]+dfs(x+2,y),a[y]+dfs(x+1,y-1));
				}else{
					dp[x][y]=max(a[x],a[y])+dfs(x+1,y-1);
				}
			}else{
				if(a[x+1]>a[y]){
					dp[x][y]=max(a[x]+dfs(x+2,y),a[y]+dfs(x,y-2));
				}else{
					dp[x][y]=max(a[x]+dfs(x+1,y-1),a[y]+dfs(x,y-2));
				}
			}
		}
		return dp[x][y];
	}
}

int main(){
	int n;
	long long int x=0;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		a[n+i]=a[i];
		fill(dp[i],dp[i]+4001,-1);
	}
	for(int i=n+1;i<=2*n;++i){
		fill(dp[i],dp[i]+4001,-1);
	}
	for(int i=1;i<=n;i+=2){
		x=max(x,dfs(i,i+n-1));
	}
	cout<<x<<endl;
}