import scala.io.StdIn.{readLine,readInt}

object Main {
  def loop(i:Int,s:Int,m:Int):Int =
    if(i==0) m
    else {
      val n = readInt
      val max = if(s+n > m) s+n else if(n>m) n else m
      val sum = if(s < 0 && n > s) n else s+n
      println("max=",max)
      println("min=",sum)
      loop(i-1,sum,max)
    }

  def main(args:Array[String]) = {
    var n = 0
    while( {n = readInt;n} != 0 ) println(loop(n,0,-100000))
  }
}