N = gets.to_i
A = gets.split.map(&:to_i)
CACHE = Array.new(N) { Array.new(N, false) }

def dfs(l, r, turn = 0)
  if turn == N - 1
    if turn % 2 == 0
      return A[l]
    else
      return -A[l]
    end
  end

  return CACHE[l][r] if CACHE[l][r]

  if turn % 2 == 0
    v1 = A[l] + dfs(l + 1, r, turn + 1)
    v2 = A[r] + dfs(l, r - 1, turn + 1)

    CACHE[l][r] = [v1, v2].max
  else
    v1 = dfs(l + 1, r, turn + 1) - A[l]
    v2 = dfs(l, r - 1, turn + 1) - A[r]

    CACHE[l][r] = [v1, v2].min
  end
end

p dfs(0, N - 1)

# p CACHE
# p CACHE[0][N - 1]
