

n = int(eval(input()))

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

db = [0] * (max(d)+1)

MOD = 998244353



#距離iの頂点の数をdb[i]に保存

for i in range(n):

    db[d[i]] += 1



if (d[0] != 0)|(db[0] != 1):

    print((0))

    exit()



ans = 1



for i in range(len(db)-1):

    ans *= pow(db[i],db[i+1],MOD)



print((ans%MOD))

n = int(eval(input()))

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

db = [0] * (max(d)+1)

MOD = 998244353



#距離iの頂点の数をdb[i]に保存

for i in range(n):

    db[d[i]] += 1



if (d[0] != 0)|(db[0] != 1):

    print((0))

    exit()



ans = 1



for i in range(len(db)-1):

    ans *= db[i]**db[i+1]%MOD



print((ans%MOD))

n = int(eval(input()))
d = list(map(int, input().split()))
db = [0] * (max(d) + 1)
MOD = 998244353
# 距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1
if (d[0] != 0) | (db[0] != 1):
    print((0))
    exit()
ans = 1
for i in range(len(db) - 1):
    ans *= pow(db[i], db[i + 1], MOD)
print((ans % MOD))

n = int(eval(input()))
d = list(map(int, input().split()))
db = [0] * (max(d) + 1)
MOD = 998244353
# 距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1
if (d[0] != 0) | (db[0] != 1):
    print((0))
    exit()
ans = 1
for i in range(len(db) - 1):
    ans *= db[i] ** db[i + 1] % MOD
print((ans % MOD))

-    ans *= pow(db[i], db[i + 1], MOD) +    ans *= db[i] ** db[i + 1] % MOD