n=int(eval(input()))

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

if l[0]:print((0));exit()

mod=998244353

k=[0]*n

for i in l:k[i]+=1

if k[0]!=1:print((0));exit()

ans=1

for i,s in zip(k,k[1:]):ans*=pow(i,s,mod)

print((ans%mod))
mod=998244353

n=int(eval(input()))

from collections import Counter as co

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

l=co(j)

ll=len(l)

for i in range(ll):

    if i not in l:print((0));exit()

if l[0]>=2 or j[0]!=0:print((0));exit()

ans=1

pre=1

for k,v in sorted(l.items()):

    ans*=pow(pre,v,mod)

    ans%=mod

    pre=v

print((ans%mod))
n = int(eval(input()))
l = list(map(int, input().split()))
if l[0]:
    print((0))
    exit()
mod = 998244353
k = [0] * n
for i in l:
    k[i] += 1
if k[0] != 1:
    print((0))
    exit()
ans = 1
for i, s in zip(k, k[1:]):
    ans *= pow(i, s, mod)
print((ans % mod))

mod = 998244353
n = int(eval(input()))
from collections import Counter as co

j = list(map(int, input().split()))
l = co(j)
ll = len(l)
for i in range(ll):
    if i not in l:
        print((0))
        exit()
if l[0] >= 2 or j[0] != 0:
    print((0))
    exit()
ans = 1
pre = 1
for k, v in sorted(l.items()):
    ans *= pow(pre, v, mod)
    ans %= mod
    pre = v
print((ans % mod))

+mod = 998244353 -l = list(map(int, input().split())) -if l[0]: -    print((0)) -    exit() -mod = 998244353 -k = [0] * n -for i in l: -    k[i] += 1 -if k[0] != 1: +from collections import Counter as co + +j = list(map(int, input().split())) +l = co(j) +ll = len(l) +for i in range(ll): +    if i not in l: +        print((0)) +        exit() +if l[0] >= 2 or j[0] != 0: -for i, s in zip(k, k[1:]): -    ans *= pow(i, s, mod) +pre = 1 +for k, v in sorted(l.items()): +    ans *= pow(pre, v, mod) +    ans %= mod +    pre = v