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

enum inf = 10L^^15;
enum mod = 10L ^^ 9 + 7;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto dp = new long[][][](n + 1, n + 1, 2);
    fillAll(dp, -1);

    long dfs(int l, int r, int p) {
        if (dp[l][r][p] != -1) {
            return dp[l][r][p];
        }
        if (r - l == 1) {
            return dp[l][r][p] = (-1)^^p * a[l];
        }
        dp[l][r][p] = (p ? min(dfs(l, r-1, p^1) - a[r-1], dfs(l+1, r, p^1) - a[l]) : 
                           max(a[r-1] + dfs(l, r-1, p^1), a[l] + dfs(l+1, r, p^1)));
        return dp[l][r][p];
    }

    auto ans = dfs(0, n, 0);

    debug {
        foreach (l ; 0 .. n) {
            foreach (r ; 0 .. n) {
                foreach (p ; 0 .. 2) {
                    if (dp[l][r][p] != -1) {
                        stderr.writefln("%d, %d, %d = %d", l, r, p, dp[l][r][p]);
                    }
                }
            }
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}