#include <stdio.h>
typedef long long ll;

ll max(ll a, ll b) {
  return a > b ? a : b;
}

int main(void) {
  ll i, j, k, n;
  scanf("%lld", &n);
  ll dp[n + 1][n], p[n * 2];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &p[i]);
    p[i + n] = p[i];
  }
  for(i = 0; i <= n; ++i) for(j = 0; j < n; ++j) dp[i][j] = 0;
  for(i = 1; i <= n; ++i) {
    if(i % 2) {
      for(j = 0; j < n; ++j) {
        ll t = j + 1;
        if(t >= n) t -= n;
        dp[i][j] = max(dp[i - 1][j] + p[i + j - 1], dp[i - 1][t] + p[j]);
      }
    } else {
      for(j = 0; j < n; ++j) {
        ll t = j - 1;
        if(t < 0) t += n;
        if(p[i + j - 1] >= p[t]) dp[i][j] = dp[i - 1][j];
        t = j + 1;
        if(t >= n) t -= n;
        if(p[i + j] <= p[j] && dp[i][j] < dp[i - 1][t]) dp[i][j] = dp[i - 1][t];
      }
    }
  }
  ll ans = 0;
  /*for(i = 1; i <= n; ++i) {
    for(j = 0; j < n; ++j) printf("%lld ", dp[i][j]);
    printf("\n");
  }*/
  for(i = 0; i < n; ++i) if(ans < dp[n][i]) ans = dp[n][i];
  printf("%lld\n", ans);
  return 0;
}
