from collections import Counter



n = int(eval(input()))

d = list(map(int, input().split()))

mod = 998244353



a = sorted(list(set(d)))



if d[0] != 0:

    ans = 0

elif a[-1] != len(a)-1:

    ans = 0

else:

    c = sorted(Counter(d).items())

    if c[0] != (0, 1):

        ans = 0

    else:

        ans = 1

        pre = 1

        for k, v in c:

            ans *= pre ** v

            ans %= mod

            pre = v



print(ans)
n = int(eval(input()))

d = list(map(int, input().split()))

mod = 998244353



a = [0] * n

for d_ in d:

    a[d_] += 1



res = d[0] == 0 and a[0] == 1

pre = 1

for a_ in a:

    res *= pre ** a_

    res %= mod

    pre = a_



print(res)
from collections import Counter

n = int(eval(input()))
d = list(map(int, input().split()))
mod = 998244353
a = sorted(list(set(d)))
if d[0] != 0:
    ans = 0
elif a[-1] != len(a) - 1:
    ans = 0
else:
    c = sorted(Counter(d).items())
    if c[0] != (0, 1):
        ans = 0
    else:
        ans = 1
        pre = 1
        for k, v in c:
            ans *= pre**v
            ans %= mod
            pre = v
print(ans)

n = int(eval(input()))
d = list(map(int, input().split()))
mod = 998244353
a = [0] * n
for d_ in d:
    a[d_] += 1
res = d[0] == 0 and a[0] == 1
pre = 1
for a_ in a:
    res *= pre**a_
    res %= mod
    pre = a_
print(res)

-from collections import Counter - -a = sorted(list(set(d))) -if d[0] != 0: -    ans = 0 -elif a[-1] != len(a) - 1: -    ans = 0 -else: -    c = sorted(Counter(d).items()) -    if c[0] != (0, 1): -        ans = 0 -    else: -        ans = 1 -        pre = 1 -        for k, v in c: -            ans *= pre**v -            ans %= mod -            pre = v -print(ans) +a = [0] * n +for d_ in d: +    a[d_] += 1 +res = d[0] == 0 and a[0] == 1 +pre = 1 +for a_ in a: +    res *= pre**a_ +    res %= mod +    pre = a_ +print(res)