#include <cstdio>
#include <algorithm>
#include <vector>
#include <deque>
#include <cstdint>

int main() {
  int N;
  scanf("%d", &N);

  std::vector<intmax_t> A(N);
  for (int i=0; i<N; ++i)
    scanf("%jd", &A[i]);

  if (N == 1) {
    printf("%jd\n", A[0]);
    return 0;
  } else if (N == 2) {
    printf("%jd\n", std::max(A[0], A[1]));
    return 0;
  }

  std::vector<std::vector<intmax_t>> dp(N, std::vector<intmax_t>(N));
  for (int i=0; i<N; ++i) {
    dp[i][i] = A[i];
  }

  // XXX half-open interval is better than this... 
  for (int i=1; i<N; ++i) {
    for (int j=0; j<N; ++j) {
      // dp[j][(i+j)%N]; haba: i, hidari: j
      // l_next, [l_cur, ..., r_cur], r_next
      int l_cur=j, r_cur=(l_cur+i+N-1)%N;
      int l_next=(l_cur-1+N)%N, r_next=(r_cur+1)%N;
      if (l_cur == r_next) {
        continue;
      }
      if (i % 2 == 0) {
        // JOI
        dp[l_cur][r_next] = std::max(dp[l_cur][r_next], dp[l_cur][r_cur]+A[r_next]);
        dp[l_next][r_cur] = std::max(dp[l_next][r_cur], dp[l_cur][r_cur]+A[l_next]);
      } else {
        // IOI
        if (A[l_next] > A[r_next]) {
          // ... eats A[l_next]
          dp[l_next][r_cur] = std::max(dp[l_next][r_cur], dp[l_cur][r_cur]);
        } else {
          dp[l_cur][r_next] = std::max(dp[l_cur][r_next], dp[l_cur][r_cur]);
        }
      }
    }
  }

#if 0
  for (int i=0; i<N; ++i) {
    for (int j=0; j<N; ++j) {
      printf("%jd%c", dp[j][(j+i)%N], j+1<N? ' ':'\n');
    }
  }
#endif

  intmax_t res=0;
  for (int i=0; i<N; ++i)
    res = std::max(res, *std::max_element(dp[i].begin(), dp[i].end()));

  printf("%jd\n", res);
  return 0;
}