main = getContents >>= mapM_ (print . maximum_sum_seq) . reverse . fin [] . map read . init . lines
fin acc [] = acc
fin acc (n:ns) = fin ((take (fromIntegral n) ns):acc) (drop (fromIntegral n) ns)
maximum_sum_seq ns = maximum ns' - minimum ns'
 where ns' = scanl (+) 0 ns