object Main extends App {

  import java.util.Scanner

  case class Solver(sum: Int, ans: Int) {
    def print() { println(ans) }
  }

  def solve(sc: Scanner, n: Int, s: Solver): Solver = {
    n match {
      case 0 => s
      case x =>
        val a = sc.nextInt()
        if (a < 0) solve(sc, x-1, s.copy(sum = 0, ans = if (s.ans < s.sum) s.sum else s.ans))
        else solve(sc, x-1, s.copy(sum = s.sum + a))
    }
  }

  def loop(sc: Scanner): Solver = {
    sc.nextInt() match {
      case 0 => Solver(0, 0)
      case n =>
        val s = solve(sc, n, Solver(0, 0))
        s.print()
        loop(sc)
    }
  }

  val sc = new Scanner(System.in)
  loop(sc)

}