n,*a=list(map(int,open(0).read().split()))

mod=998244353

d={}

for i in a:

  d[i]=d.get(i,0)+1

b=list(d.items())

b.sort()

ans=1

if a[0]!=0 or len(b)!=b[-1][0]+1 or b[0][1]!=1:

    ans=0

for i in range(1,len(b)):

    ans*=b[i-1][1]**b[i][1]

    ans%=mod

print(ans)
n,*a=list(map(int,open(0).read().split()))

mod=998244353

b=[0]*n

for i in a:

    b[i]+=1

ans=0

if a[0]==0 and 1==b[0]:

    ans=1

for i,j in zip(b,b[1:]):

    ans=ans*i**j%mod

print(ans)
n, *a = list(map(int, open(0).read().split()))
mod = 998244353
d = {}
for i in a:
    d[i] = d.get(i, 0) + 1
b = list(d.items())
b.sort()
ans = 1
if a[0] != 0 or len(b) != b[-1][0] + 1 or b[0][1] != 1:
    ans = 0
for i in range(1, len(b)):
    ans *= b[i - 1][1] ** b[i][1]
    ans %= mod
print(ans)

n, *a = list(map(int, open(0).read().split()))
mod = 998244353
b = [0] * n
for i in a:
    b[i] += 1
ans = 0
if a[0] == 0 and 1 == b[0]:
    ans = 1
for i, j in zip(b, b[1:]):
    ans = ans * i**j % mod
print(ans)

-d = {} +b = [0] * n -    d[i] = d.get(i, 0) + 1 -b = list(d.items()) -b.sort() -ans = 1 -if a[0] != 0 or len(b) != b[-1][0] + 1 or b[0][1] != 1: -    ans = 0 -for i in range(1, len(b)): -    ans *= b[i - 1][1] ** b[i][1] -    ans %= mod +    b[i] += 1 +ans = 0 +if a[0] == 0 and 1 == b[0]: +    ans = 1 +for i, j in zip(b, b[1:]): +    ans = ans * i**j % mod