import java.io.{BufferedReader, InputStreamReader}

import scala.collection.mutable

object Main {
  val MODULO = 998244353L

  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).sorted.toList

    var result = 0L

    if (ds.head == 0 && (ds.tail == Nil || ds.tail.head == 1)) {
      result = 1L
      var lastElementCount = 1

      ds = ds.tail
      for (i <- 1 until n if ds.nonEmpty) {
        ds.span(_ == i) match {
          case (as, bs) =>
            for (_ <- as.indices) {
              result = result * lastElementCount % MODULO
            }
            lastElementCount = as.length
            ds = bs
        }
      }
    } else {
      result = 0L
    }

    System.out.println(
      result
    )
  }
}
