import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Vector as V
--import qualified Data.Function.Memoize as Memo
import Debug.Trace as De

getIntList = map read . words <$> getLine


listToTriple abc =(a,b,c)
    where [a,b,c]=abc
main :: IO ()

fir (a,_,_)=a
sec (_,b,_)=b
trd (_,_,c)=c

culc:: Int -> V.Vector Int -> Int
culc n av = solve 0 (n-1)
    where 
        dp=V.generate n (\i -> V.generate n (solve i))
        solve :: Int -> Int -> Int
        solve l r 
            | l==r = av V.! l
            | otherwise = max ((av V.! l)-( (dp V.! (l+1)) V.! r)) ((av V.! r)- ( (dp V.! l) V.! (r-1)) )
            

main = do
    nstr <-getLine
    inas <- getIntList 
    let av=(V.fromList inas) ::V.Vector Int
    let n = read nstr
    putStrLn(show (culc n av))
    


    

