N = int(eval(input()))

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

mod = 998244353

ans = 1

A = [0]*(max(D)+1)

for i in range(N):

  A[D[i]] += 1

#if D[0] != 0 or not all(D[1:]) or not all(A):

#  print(0)

#  exit()

if D[0] != 0 or not all(D[1:]):

  print((0))

  exit()

for i in range(1, max(D)+1):

#  print(A[i])

  if A[i] == 0:

    print((0))

    exit()

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

print((ans % mod))
N = int(eval(input()))

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

mod = 998244353

ans = 1

A = [0]*(max(D)+1)

for i in range(N):

  A[D[i]] += 1

if D[0] != 0 or not all(D[1:]) or not all(A):

  print((0))

  exit()

for i in range(1, max(D)+1):

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

print((ans % mod))
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0] * (max(D) + 1)
for i in range(N):
    A[D[i]] += 1
# if D[0] != 0 or not all(D[1:]) or not all(A):
#  print(0)
#  exit()
if D[0] != 0 or not all(D[1:]):
    print((0))
    exit()
for i in range(1, max(D) + 1):
    #  print(A[i])
    if A[i] == 0:
        print((0))
        exit()
    ans = ans * pow(A[i - 1], A[i], mod) % mod
print((ans % mod))

N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0] * (max(D) + 1)
for i in range(N):
    A[D[i]] += 1
if D[0] != 0 or not all(D[1:]) or not all(A):
    print((0))
    exit()
for i in range(1, max(D) + 1):
    ans = ans * pow(A[i - 1], A[i], mod) % mod
print((ans % mod))

-# if D[0] != 0 or not all(D[1:]) or not all(A): -#  print(0) -#  exit() -if D[0] != 0 or not all(D[1:]): +if D[0] != 0 or not all(D[1:]) or not all(A): -    #  print(A[i]) -    if A[i] == 0: -        print((0)) -        exit()