#include <iostream>
#include <vector>

int N = 1;
std::vector<int> v(10000);
std::vector<std::vector<long long>> dp(10000, std::vector<long long>(2, 0));

#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))

int main() {
    while (N != 0) {
        std::cin >> N;
        if (N == 0) {
            break;
        }

        for (int i = 0; i < N; ++i) {
            std::cin >> v[i];
        }

        for (int i = 0; i < N - 1; ++i) {
            dp[i][0] = max(v[i], v[i + 1]);
        }

        int turn = 0;
        int pastTurn = 1;

        for (int intervalSize = 4; intervalSize <= N; intervalSize += 2) {
            pastTurn = turn;
            turn = (!(turn & 1));

            for (int i = 0, j = intervalSize - 1; j < N; ++i, ++j) {
                dp[i][turn] = max(v[i] + min(dp[i + 1][pastTurn], dp[i + 2][pastTurn]),
                                  v[j] + min(dp[i][pastTurn], dp[i + 1][pastTurn]));
            }
        }

        std::cout << dp[0][turn] << std::endl;
    }

    return 0;
}