#include <bits/stdc++.h>

using namespace std;

typedef long long Int;

Int memo[4096][4096];
int A[4096], N;

Int getMax(int L, int R)
{
    if (R - L + 1 <= 2){
        return (max(A[L], A[R]));
    }
    if (~memo[L][R]) return (memo[L][R]);
    
    Int ans1 = 0, ans2 = 0;
    ans1 = A[L] + (A[L + 1] > A[R] ? getMax(L + 2, R) : getMax(L + 1, R - 1));
    ans2 = A[R] + (A[L] < A[R - 1] ? getMax(L, R - 2) : getMax(L + 1, R - 1));
    
    memo[L][R] = max(ans1, ans2);
    if (R + N < 2 * N) memo[L + N][R + N] = memo[L][R];
    if (L - N >= 0) memo[L - N][R - N] = memo[L][R];
    
    return (memo[L][R]);
}

int main()
{
    scanf("%d", &N);
    
    for (int i = 0; i < N; i++){
        scanf("%d", A + i);
        A[i + N] = A[i];
    }
    
    memset(memo, -1, sizeof(memo));
    
    Int ans = 0;
    for (int i = 0; i < N; i++){
        ans = max(ans, getMax(i, i - 1 + N));
    }
    
    printf("%lld\n", ans);
    
    return (0);
}