import scala.io.StdIn._
object Main extends App {
  var stack = List((0L, -1))
  val n = readInt()
  val height = readLine.trim.split(' ').map(_.toLong)
  var max = 0L
  for ((h, i) ← height.zipWithIndex) {
    val (greater, lesser) = stack.span(_._1 >= h)
    var last = i
    for ((g, gi) ← greater) {
      if (max < g * (i - gi)) max = g * (i - gi)
      last = gi
    }
    stack = (h, last)::lesser
  }
  if (stack.nonEmpty && max < stack.map{case (h, i) ⇒ h * (n - i)}.max) max = stack.map{case (h, i) ⇒ h * (n - i)}.max
  println(max)
}

