fun main(args: Array<String>) {
    nikkei20192quala_b()
}

private fun mod(x: Long) = x % (998244353).toLong()

fun nikkei20192quala_b() {
    val n = readLine()!!.toInt()
    val dList = readLine()!!.split(" ").map { it.toInt() }

    if (dList.first() != 0) return println(0)

    val eachCount = dList.groupBy { it }.mapValues { it.value.size }

    if (eachCount[0] != 1) return println(0)

    var answer = 1L
    var depth = 0
    while (eachCount[depth + 1] != null) {
        depth++
        (1..eachCount[depth]!!).forEach { answer = mod(answer * eachCount[depth - 1]!!) }
    }

    if (depth < dList.max()!!) return println(0)

    println(answer)
}
