import Control.Applicative ((<$>), (<*>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr) import Data.Char (isSpace) main :: IO () main = solve <$> readLn <*> (readil B.readInt <$> B.getLine) >>= print solve :: Int -> [Int] -> Int solve n (v:vs) = dp !! n where dp = 0 : v : unfoldr f (0, vs) where f (_, []) = Nothing f (i, (x:xs)) = Just (max (dp !! (i+1)) (x + dp !! i), (i+1, xs)) readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')