#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 2001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int INF = 1e9;
#define B 100
ll solve1(int, int);

ll n, a[MAX], dp[MAX][MAX];
int con(int k){
	if(k > n)k = 1;
	if(k == 0)k = n;
	return k;
}

ll solve2(int l, int r){
	l = con(l);r = con(r);
	if(l == r)return 0;
	if(a[l] < a[r])r = con(r-1);
	else if(a[r] < a[l])l = con(l+1);
	return solve1(l, r);
}

ll solve1(int l, int r){
	l = con(l);r = con(r);
	if(l == r)return a[l];
	if(dp[l][r] != 0)return dp[l][r];
	ll v = max(solve2(l, r-1)+a[r], solve2(l+1, r)+a[l]);
	dp[l][r] = max(dp[l][r], v);
	return dp[l][r];
}

int main(){
	ll ans = 0;
	scanf("%d", &n);
	rrep(i,n)scanf("%d", &a[i]);
	for(int i = 1;i <= n;i++){
		ans = max(ans, solve1(i+1, i));
	}
	printf("%lld\n", ans);
	return 0;
}