object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    var n = 0
    var ans = Array[Int]()
    var list = Array[Int]()
    while (sc.hasNext) {
      n = sc.nextInt
      if (n == 0) {
        sys.exit
      }
      ans = Array[Int](n * n)
      list = Array[Int](n)
      for (in <- 0 until n) list = list :+ sc.nextInt
      (1 to n).foreach(i => (0 until n).foreach(j => ans = ans :+ list.tail.drop(n - i).dropRight(j).sum))
      println(ans.tail.max)
    }
  }
}