import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;

    auto mem = new long[][](N, N);
    auto used = new bool[][](N, N);

    long dfs(int t, int a, int b) {
        if (a > b) return 0;
        if (used[a][b]) return mem[a][b];
        if (t == 0) {
            mem[a][b] = max(dfs(t^1, a+1, b) + A[a], dfs(t^1, a, b-1) + A[b]);
        } else {
            mem[a][b] = min(dfs(t^1, a+1, b) - A[a], dfs(t^1, a, b-1) - A[b]);
        }
        used[a][b] = true;
        return mem[a][b];
    }

    dfs(0, 0, N-1).writeln;
}
