import scala.io.StdIn.readLine

object Main {

  def loop(max:Int, sum:Int, i:Int):Int = {
    i match {
      case 0 => if( sum > max ) sum else max
      case i =>
        val m = readLine().toInt
        val (x,y) =
          if(sum < 0 && m > sum) (max,m)
          else if(m < 0 && sum > max) (sum,sum+m)
          else (max, sum+m)
        loop(x,y,i-1)
    }
  }

  def main(args: Array[String]) = {
    val b = new StringBuilder

    var n = readLine().toInt
    while(n!= 0) {
      b.append(loop(-100000, readLine().toInt, n-1).toString)
      b.append("\n")
      n = readLine().toInt
    }

    print(b.result)
  }
}