import Control.Monad

type Fst_count = Int
type Snd_count = Int
type Dropped = Int
type Fst = Int
type Snd = Int
type Limit = Int
search :: [Int] -> Fst_count -> Snd_count -> Dropped -> Fst -> Snd -> Limit -> Int
search a@(x:xs) fc sc d f s lim
  | fc == lim && sc == lim = f - s
  | fc /= lim = if d /= lim then max (search xs fc sc (d + 1) f s lim) (search xs (fc + 1) sc d (f + x) s lim) else search xs (fc + 1) sc d (f + x) s lim
  | sc /= lim = if d /= lim then max (search xs fc sc (d + 1) f s lim) (search xs fc (sc + 1) d f (s + x) lim) else (f - (s + sum a))

main = do
  [n] <- map read . words <$> getLine :: IO [Int]
  in_seq <- map read . words <$> getLine :: IO [Int]

  let ans = search in_seq 0 0 0 0 0 n

  print ans
