mod = 998244353

n=int(eval(input()))

d=[int(i) for i in input().split()]

ans=[0]*n

for i in d:

    ans[i]+=1

f=mod

for i in ans:

    if f==0 and i>0:

        print((0))

        exit()

    f=min(f,i)

if d.count(0)!=1 or d[0]!=0:

    print((0))

    exit()

cnt=1

for i in range(1,n):

    if ans[i-1]==0:

        break

    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod



print((cnt%mod))
mod = 998244353

n=int(eval(input()))

d=[int(i) for i in input().split()]

ans=[0]*n

for i in d:

    ans[i]+=1

f=mod

for i in ans:

    if f==0 and i>0:

        print((0))

        exit()

    f=min(f,i)

if d.count(0)!=1 or d[0]!=0:

    print((0))

    exit()

cnt=1

if ans[2]==0:

    print((1))

    exit()

for i in range(1,n):

    if ans[i]==0:

        break

    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod

 

print((cnt%mod))
mod = 998244353
n = int(eval(input()))
d = [int(i) for i in input().split()]
ans = [0] * n
for i in d:
    ans[i] += 1
f = mod
for i in ans:
    if f == 0 and i > 0:
        print((0))
        exit()
    f = min(f, i)
if d.count(0) != 1 or d[0] != 0:
    print((0))
    exit()
cnt = 1
for i in range(1, n):
    if ans[i - 1] == 0:
        break
    cnt = cnt * pow(ans[i - 1], ans[i], mod) % mod
print((cnt % mod))

mod = 998244353
n = int(eval(input()))
d = [int(i) for i in input().split()]
ans = [0] * n
for i in d:
    ans[i] += 1
f = mod
for i in ans:
    if f == 0 and i > 0:
        print((0))
        exit()
    f = min(f, i)
if d.count(0) != 1 or d[0] != 0:
    print((0))
    exit()
cnt = 1
if ans[2] == 0:
    print((1))
    exit()
for i in range(1, n):
    if ans[i] == 0:
        break
    cnt = cnt * pow(ans[i - 1], ans[i], mod) % mod
print((cnt % mod))

+if ans[2] == 0: +    print((1)) +    exit() -    if ans[i - 1] == 0: +    if ans[i] == 0: