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

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

maximum_sum_seq ns = if all (<0) (tail ns') then maximum ns else maxgain
 where
  maxgain= maximum $ map (\xs -> maximum xs - head xs) $ init $ tails ns'
  ns' = scanl (+) 0 ns