#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

long long int a[2000],n,memo[2000][2000];
bool done[2000][2000];

long long int search(long long int left,long long int right){
    long long int x,y,old;
    if(done[left][right]){
        return memo[left][right];
    }
    done[left][right]=true;
    if(left==right){
        memo[left][right]=0LL;
        return memo[left][right];
    }
    if((left+n-1)%n==right){
        memo[left][right]=min(a[left],a[right]);
        return memo[left][right];
    }
    if(a[left]>a[right]){
        x = (left+n-1)%n;
        y = right;
    }else{
        x = left;
        y = (right+1)%n;
    }
    memo[left][right]=max(search((x+n-1)%n,y)+a[x],search(x,(y+1)%n)+a[y]);
    return memo[left][right];
}

int main(void){
    long long int i,j,ans=-1;
    scanf("%lld",&n);
    for(i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for(i=0; i<n; i++){
        for(j=0; j<n; j++){
            done[i][j]=false;
        }
    }
    for(i=0; i<n; i++){
        ans = max(search((i+n-1)%n,(i+1)%n)+a[i],ans);
    }
    printf("%lld\n",ans);
    return 0;
}