local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local function tostringx(o)if type(o) == 'table' then local keys = {}for k in pairs(o) do table.insert(keys, k) end table.sort(keys)local inside = {}for i=1,#keys do local k = keys[i]local v = o[k]if type(k) == 'string' then k = string.format('%q', k)end table.insert(inside, '['..k..'] = ' .. tostringx(v))end return '{' .. table.concat(inside, ', ') .. '}'else if type(o) == 'string' then o = string.format('%q', o)end return tostring(o)end end
----
local N = read.n()
local A = read.N(N)
local t = array(2)
for i=1,N do
    t[i][i] = A[i]
end
local function rec(i, j)
    if t[i][j] then
        return t[i][j]
    end
    local ri = A[j] - rec(i, j-1)
    local le = A[i] - rec(i+1, j)
    local ret = math.max(ri, le)
    t[i][j] = ret
    return ret
end
print(rec(1, N))