object Main {
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.toInt)
        for (n <- in if n != 0) println(in.take(n).scanLeft(0)((a, b) => b max (a+b)).max)
    }
}