import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    var ds = in.readLine().split("\\s+").map(_.toInt)

    var result = 0
    var lastElementCount = 0

    for (i <- 0 until n if ds.nonEmpty) {
      System.err.println(ds.mkString(",") + "=>" + result)
      if (i == 0) {
        if (ds(0) == 0 && ds.count(_ == 0) == 1) {
          result = 1
          lastElementCount = 1
          ds = ds.filter(_ != 0)
        }
        else {
          result = 0
          lastElementCount = 0
          ds = Array()
        }
      } else {
        ds.partition(_ == i) match {
          case (as, bs) =>
            result = result * Math.pow(lastElementCount, as.length).toInt
            lastElementCount = as.length
            ds = bs
        }
      }
    }

    System.out.println(
      result
    )
  }
}
