import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val n = readInt
      if (n == 0) return
      var sum = 0
      var max = Int.MinValue
      for (i <- 0 until n) {
        val x = readInt
        sum += x
        if (sum < 0) {
          sum = 0
        }
        max = Math.max(max, sum)
      }
      println(max)
    }
  }
}