val MOD = 998244353

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val dd = readLine()!!.split(" ").map{it.toInt()}

    if (dd[0] != 0) {
        println(0)
        return
    }

    val groups = mutableMapOf<Int, Int>()
    var max = 0
    dd.forEach {
        groups[it] = (groups[it] ?: 0) + 1
        if (it > max) max = it
    }

    if (groups[0]!! > 1) {
        println(0)
        return
    }

    var sum = 1L
    for (i in max downTo 1) {
        val cnt = groups[i] ?: 0
        val nextCnt = groups[i-1] ?: 0
        if (cnt == 0 || nextCnt == 0) {
            println(0)
            return
        }

        sum *= modPow(nextCnt, cnt)
        sum %= MOD
    }

    println(sum % MOD)
}

fun modPow(base: Int, pow: Int): Long {
    var ans = 1L
    repeat(pow) {
        ans *= base
        ans %= MOD
    }
    return ans
}