object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val n = readInt
      if (n == 0) return

      var list: Array[Long] = Array.empty
      for (i <- 0 until n) {
        list :+= readInt.toLong
      }
      println(execute(list))
    }

    //println(execute(Array(-5, -1, 6, 4, 9, -6)))
    //println(execute(Array(-5, -1, -5)))
  }

  def execute(list: Array[Long]): Long = {

    var max = list(0)

    for (i <- 0 until list.length) {
      val result = new Array[Long](list.length)
      result(i) = list(i)
      max = Math.max(result(i), max)
      for (j <- i + 1 until list.length) {
        result(j) = list(j) + result(j - 1)
        max = Math.max(result(j), max)
      }
      result.foreach(x => print(x + " "))
      println()
    }

    max
  }
}