#include<bits/stdc++.h>
#define int long long
using namespace std;

int a[4000]; int memo[4000][4000];
int saiki(int a, int b) {
	if (memo[a][b] != -1)return memo[a][b];
	if (a > b)return 0;
	if ((b - a) & 1) {//??????
		int S = 0;
		if (::a[a] >= ::a[b + 1]&&::a[b+1]!=0)S = saiki(a + 1, b);
		if (::a[a - 1] <= ::a[b]&&::a[a-1]!=0)S = max(S, saiki(a, b - 1));
		return memo[a][b]=S;
	}
	else {//??????
		return memo[a][b]=max(saiki(a + 1, b) + ::a[a], saiki(a, b - 1) + ::a[b]);
	}
	return 0;
}
signed main() {
	memset(memo, -1, sizeof(memo));
	int b;
	cin >> b;
	for (int c = 0; c < b; c++) {
		scanf("%lld", &a[c]);
		a[b + c] = a[c];
	}
	int MAX = 0;
	for (int d = 1; d <= b; d++) {
		MAX = max(MAX, saiki(d, d + b - 1));
	}
	cout << MAX << endl;
}