local n=io.read("n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local dp={}
local flag={}
for i=1,n do
    dp[i]={}
    flag[i]={}
    for j=1,n do
        dp[i][j]=0
    end
end

local function solve(i,j)
    if flag[i][j] then
        return dp[i][j]
    end
    flag[i][j]=true
    if i==j then
        dp[i][j]=a[i]
        return dp[i][j]
    end
    dp[i][j]=math.max(a[i]-solve(i+1,j),a[j]-solve(i,j-1))
    return dp[i][j]
end

print(solve(1,n))