import std.container;
import std.range;
import std.algorithm;
import std.array;
import std.string;
import std.conv;
import std.stdio;
import std.container;

void main() {
	auto n = readln.chomp.to!int;
	auto a = readln.chomp.split(' ').map!(to!long).array;
	auto dp = new long[][](n + 1, n + 1);
	foreach (l;dp) {
		l[] = -1;
	}

	long solve(int turn, size_t f, size_t l) {
		if (f >= l) return 0;

		if (dp[f][l] != -1) {
			return dp[f][l];
		}

		if (turn == 0) {
			auto p0 = solve(1, f + 1, l) + a[f];
			auto p1 = solve(1, f, l - 1) + a[l - 1];
			auto result = max(p0, p1);
			dp[f][l] = result;
			return result;
		} else {
			auto p0 = solve(0, f + 1, l) - a[f];
			auto p1 = solve(0, f, l - 1) - a[l - 1];
			auto result = min(p0, p1);
			dp[f][l] = result;
			return result;
		}
	}

	writeln(solve(0, 0, a.length));
}
