import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.datetime;
import std.numeric;
import std.math;
import std.string;

string my_readln() { return chomp(readln()); }

void main()
{
	auto tokens = my_readln().split();
	auto N = tokens[0].to!uint;
	long[] a;
	foreach (token; my_readln.split)
	{
		a ~= token.to!long;
	}

	auto dp = new long[][](3005, 3005);

	foreach_reverse (i; 0..N)
	{
		foreach (j; i+1..N+1)
		{
			long turn = (N - (j - i)) % 2 == 0 ? 1 : -1; 
			auto r1   = dp[i][j-1] + a[j-1] * turn;
			auto r2   = dp[i+1][j] + a[i] * turn;
			auto r    = turn == 1 ? max(r1, r2) : min(r1, r2);
			dp[i][j]  = r;
		}
	}

	writeln(dp[0][N]);
	stdout.flush();
}