#include <bits/stdc++.h>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

int n;
ll A[2048];
ll memo[2048][2048];

ll joi(int l, int r);
ll ioi(int l, int r);

ll joi(int l, int r) {
  // cout << "joi" << l << r << endl;
  if (l == r) return A[l];
  if (r < 0) return joi(l, r + n);
  if (l >= n) return joi(l - n, r);
  if (memo[l][r] != -1) return memo[l][r];
  return memo[l][r] = max(A[l] + ioi(l + 1, r), A[r] + ioi(l, r - 1));
}

ll ioi(int l, int r) {
  // cout << "ioi" << l << r << endl;
  if (l == r) return 0;
  if (r < 0) return ioi(l, r + n);
  if (l >= n) return ioi(l - n, r);
  if (memo[l][r] != -1) return memo[l][r];
  if (A[l] < A[r]) return memo[l][r] = joi(l, r - 1);
  return memo[l][r] = joi(l + 1, r);
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);
  memset(memo, -1, sizeof(memo));
  cin >> n;
  REP(i,n) cin >> A[i];
  ll res = 0;
  REP(i,n) {
    chmax(res, A[i] + ioi(i + 1, i - 1));
  }
  cout << res << endl;
  return 0;
}