import java.util.Scanner
import kotlin.system.exitProcess

val MOD = 998244353

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val ds = IntArray(n){scn.nextInt()}.toMutableList()
	if (ds[0]!=0) retire()
	ds.removeAt(0)
	ds.sort()
	if (ds[0]!=1) retire()
	var ans = 1L
	var l = 1
	var cntBef = 1
	var cnt = 0
	for (d in ds){
		when(d){
			l -> cnt++
			l+1 -> {
				ans = (ans*powMod(cntBef, cnt))%MOD
				cntBef = cnt
				cnt = 1
				l++
			}
			else -> retire()
		}
	}
	if (cnt!=0) ans = (ans*powMod(cntBef, cnt))%MOD
	println(ans)
}

fun powMod(b: Int, e: Int): Long{
	if (b==1) return 1
	var ans = 1L
	var b = b.toLong()
	var e = e
	while (e!=0){
		if (e%2==1) ans = (ans*b)%MOD
		b = (b*b)%MOD
		e /= 2
	}
	return ans
}

fun retire(){
	println(0)
	exitProcess(0)
}