#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

//int dy[]={0, 0, 1, -1, 0};
//int dx[]={1, -1, 0, 0, 0};

#define int long long

vector<vector<int> > dp(5000, vector<int>(5000, -1));
vector<int> v(6000);
int n;

int dfs(int l, int r){
  if(dp[l][r]!=-1) return dp[l][r];

  int ret;
  if(r-l-1==n) ret=0;
  else if((l-r-1)&1){
    if(v[l]>v[r]){
      ret=dfs(l-1, r);
    }
    else{
      ret=dfs(l, r+1);
    }
  }
  else{
    ret=max(dfs(l-1, r)+v[l], dfs(l, r+1)+v[r]);
  }

  return dp[l][r]=ret;
}

signed main(){
  scanf("%lld", &n);
  REP(i, n){
    int a;
    scanf("%lld", &a);
    v[i]=v[n+i]=v[n*2+i]=a;
  }
  
  int ans=0;
  REP(i, n){
    ans=max(ans, dfs(i+n-1, i+n+1)+v[i]);
  }

  printf("%lld\n", ans);
}