import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable

object Main {
  val MODULO = 998244353
  val powMemo = new mutable.HashMap[(Int, Int), Int]

  def pow(a: Int, b: Int): Int = {
    powMemo.getOrElseUpdate((a, b), {
      if (b == 0) {
        1
      } else if (b % 2 == 0) {
        pow(a, b / 2) * pow(a, b / 2) % MODULO
      } else {
        pow(a, b - 1) * a % MODULO
      }
    })
  }

  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 * pow(lastElementCount, as.length) % MODULO
            lastElementCount = as.length
            ds = bs
        }
      }
    }

    System.out.println(
      result
    )
  }
}
