N = gets.to_i
arr = gets.split.map(&:to_i)
dp = Array.new(N).map{Array.new(N)}
N.times.each do |i|
  dp[i][i] = arr[i]
end

(1..(N-1)).each do |length|
  (0..(N-1)).each do |left|
    right = left + length
    next if right >= N
    dp[left][right] = [arr[left] - dp[left + 1][right], arr[right] - dp[left][right - 1]].max
  end
end
puts dp.first.last