{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.List
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
import Data.Vector.Unboxed as V hiding(map,minimum,maximum,forM,forM_)
import Control.Monad
import Control.Monad.State
import Control.Monad.ST

type DP s = STUArray s (Int,Int) Int
--True == Taro, False == Jiro

dp_i :: DP s -> Bool -> Vector Int -> Int -> Int -> Int -> ST s ()
dp_i dparr human as n i j = do
    left  <- readArray dparr (i+1,j)
    right <- readArray dparr (i,j-1)
    let prior human l r = if human then max (l+(as V.! (i-1))) (r+(as V.! (j-1))) else min (l-(as V.! (i-1))) (r-(as V.! (j-1)))
    writeArray dparr (i,j) $ prior human left right

solve :: Int -> Vector Int -> ST s Int
solve n as = do
  dparr <- newArray ((0,0),(n+1,n+1)) 0
  forM_ [0..n-1] $ \k ->
    forM_ [1..n-k] $ \i -> if (n-k) `mod` 2 == 1 then dp_i dparr True as n i (i+k) else dp_i dparr False as n i (i+k)
  readArray dparr (1,n)

main :: IO ()
main = do
  n  <- read <$> getLine
  as <- map read.words <$> getLine
  putStrLn $ show $ runST $ solve n (V.fromList as)
