object Main extends App {
  import scala.annotation.tailrec
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    val n = readInt()
    if (n == 0) return
    val pipe = readLine.trim.split(' ').map(_.toInt).sum
    val joint = 0L +: readLine.trim.split(' ').map(_.toLong).sorted(Ordering.Long.reverse)
    for (i ← joint.indices.tail) joint(i) += joint(i - 1)
    println(joint.zipWithIndex.map { case (additional, count) ⇒ (pipe + additional) * (n - count) }.max)
    loop()
  }
}
