open Printf

let n = int_of_string @@ read_line ()
let a =
  Str.split (Str.regexp " ") @@ read_line ()
  |> List.map int_of_string
  |> (fun l -> 0 :: l)
  |> Array.of_list

let memo = Array.make_matrix (n+1) (n+1) max_int

let rec solve: int -> int -> bool -> int = fun bg ed turn ->
  if memo.(bg).(ed) <> max_int then
    memo.(bg).(ed)
  else (
    if bg = ed then begin
      memo.(bg).(ed) <- a.(bg) * (if turn then 1 else -1);
      memo.(bg).(ed)
    end
    else (
      let left = solve (bg+1) ed (not turn) in
      let right = solve bg (ed-1) (not turn) in
      if turn then
        memo.(bg).(ed) <- max (left + a.(bg)) (right + a.(ed))
      else
        memo.(bg).(ed) <- min (left - a.(bg)) (right - a.(ed));
      memo.(bg).(ed)
    )
  )

let () =
  solve 1 n true
  |> string_of_int
  |> print_endline
