object Main extends App {
  val src = io.Source.stdin.getLines.map(_.toInt)

  val formattedSrc: List[List[Int]] = ((for (n <- src if n != 0) yield (src.take(n).toList)).toList)

  def transformList(li: List[Int]): IndexedSeq[List[Int]] =
    for { i <- 0 to li.length } yield { li.drop(i) }

  def findMax(li: IndexedSeq[List[Int]]) = (0 /: li)(returnBigger)

  def returnBigger(a: Int, b: List[Int]): Int = {
    val maxB = scanMax(b)
    if (a > maxB) a else maxB
  }

  def scanMax(li: List[Int]) = li.scanLeft(0)(_+_).max

  formattedSrc.map(a => findMax(transformList(a))).foreach(println)

}