def max(a, b)
  a > b ? a : b
end
def min(a, b)
  a < b ? a : b
end

N = gets.to_i
a = gets.split.map(&:to_i)
dp = Array.new(N + 2){Array.new(N + 2, 0)}

1.upto(N + 1) do |len|
  (N + 1 - len).times do |i|
    j = i + len
    if (N - len) % 2 == 0
      dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1])
    else
      dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1])
    end
  end
end
puts dp[0][N]