import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import Data.Array.Unboxed
import Data.Array.IO
import Control.Monad
import Data.Char
import Data.Maybe

solve :: Int -> VU.Vector Int -> IO Int 
solve n xs = do
    dp <- newArray ((0,0),(n,n)) 0 :: IO (IOUArray (Int,Int) Int)
    forM_ [1..n] $ \l ->
       if even $ n-l 
           then
                forM_ [0..n-l] $ \i -> do
                    let j = i + l
                    a <- (+ (xs VU.! i)) <$> readArray dp (i+1,j) 
                    b <- (+ (xs VU.! (j-1))) <$> readArray dp (i,j-1) 
                    writeArray dp (i,j) $! max a b
           else
                forM_ [0..n-l] $ \i -> do
                    let j = i + l
                    a <- (flip (-) (xs VU.! i)) <$> readArray dp (i+1,j) 
                    b <- (flip (-) (xs VU.! (j-1))) <$> readArray dp (i,j-1) 
                    writeArray dp (i,j) $! min a b
    readArray dp (0,n)
                   
main = do
    n <- readLn :: IO Int
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    solve n as >>= print