import Data.List
main = interact $ unlines . map (show . maximum_sum_seq) . groupProb . map read . lines

groupProb [] = []
groupProb (0:_) = []
groupProb (n:ns) = (take (fromIntegral n) ns) : groupProb (drop (fromIntegral n) ns)

maximum_sum_seq ns = maximum $ map (\xs -> maximum xs - head xs) $ init $ tails ns'
 where ns' = scanl (+) 0 ns