INFTY = 998244353

N = int(eval(input()))

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

C = {}

dmax = 0

for i in range(N):

    d = D[i]

    dmax = max(dmax,d)

    if d not in C:

        C[d] = 0

    C[d] += 1

if D[0]!=0 or C[0]!=1:

    flag = 1

else:

    flag = 0

    for i in range(dmax+1):

        if i not in C:

            cnt = 0

            flag = 1

            break

if flag==1:

    cnt = 0

else:

    cnt = 1

    for i in range(1,dmax):

        cnt = (cnt*(C[i]**C[i+1]))%INFTY

print(cnt)
p=998244353

def pow(x,m):

    if m==0:

        return 1

    if m==1:

        return x

    if m%2==0:

        return (pow(x,m//2)**2)%p

    else:

        return (x*(pow(x,(m-1)//2)**2)%p)%p

N = int(eval(input()))

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

D.insert(0,0)

C = {i:0 for i in range(N)}

for i in range(1,N+1):

    C[D[i]] += 1

if C[0]!=1 or D[1]!=0:

    cnt = 0

else:

    ind = 0

    for i in range(N):

        if C[i]==0:

            ind = i

            break

    flag = 0

    if ind>0:

        for i in range(ind+1,N):

            if C[i]>0:

                flag = 1

                break

    if flag==1:

        cnt = 0

    else:

        C = sorted(list(C.items()),key=lambda x:x[0])

        cnt = 1

        for i in range(1,N):

            if C[i][1]==0:break

            c0 = C[i-1][1]

            c1 = C[i][1]

            cnt = (cnt*(pow(c0,c1)))%p

print(cnt)
INFTY = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
C = {}
dmax = 0
for i in range(N):
    d = D[i]
    dmax = max(dmax, d)
    if d not in C:
        C[d] = 0
    C[d] += 1
if D[0] != 0 or C[0] != 1:
    flag = 1
else:
    flag = 0
    for i in range(dmax + 1):
        if i not in C:
            cnt = 0
            flag = 1
            break
if flag == 1:
    cnt = 0
else:
    cnt = 1
    for i in range(1, dmax):
        cnt = (cnt * (C[i] ** C[i + 1])) % INFTY
print(cnt)

p = 998244353


def pow(x, m):
    if m == 0:
        return 1
    if m == 1:
        return x
    if m % 2 == 0:
        return (pow(x, m // 2) ** 2) % p
    else:
        return (x * (pow(x, (m - 1) // 2) ** 2) % p) % p


N = int(eval(input()))
D = list(map(int, input().split()))
D.insert(0, 0)
C = {i: 0 for i in range(N)}
for i in range(1, N + 1):
    C[D[i]] += 1
if C[0] != 1 or D[1] != 0:
    cnt = 0
else:
    ind = 0
    for i in range(N):
        if C[i] == 0:
            ind = i
            break
    flag = 0
    if ind > 0:
        for i in range(ind + 1, N):
            if C[i] > 0:
                flag = 1
                break
    if flag == 1:
        cnt = 0
    else:
        C = sorted(list(C.items()), key=lambda x: x[0])
        cnt = 1
        for i in range(1, N):
            if C[i][1] == 0:
                break
            c0 = C[i - 1][1]
            c1 = C[i][1]
            cnt = (cnt * (pow(c0, c1))) % p
print(cnt)

-INFTY = 998244353 +p = 998244353 + + +def pow(x, m): +    if m == 0: +        return 1 +    if m == 1: +        return x +    if m % 2 == 0: +        return (pow(x, m // 2) ** 2) % p +    else: +        return (x * (pow(x, (m - 1) // 2) ** 2) % p) % p + + -C = {} -dmax = 0 -for i in range(N): -    d = D[i] -    dmax = max(dmax, d) -    if d not in C: -        C[d] = 0 -    C[d] += 1 -if D[0] != 0 or C[0] != 1: -    flag = 1 -else: -    flag = 0 -    for i in range(dmax + 1): -        if i not in C: -            cnt = 0 -            flag = 1 -            break -if flag == 1: +D.insert(0, 0) +C = {i: 0 for i in range(N)} +for i in range(1, N + 1): +    C[D[i]] += 1 +if C[0] != 1 or D[1] != 0: -    cnt = 1 -    for i in range(1, dmax): -        cnt = (cnt * (C[i] ** C[i + 1])) % INFTY +    ind = 0 +    for i in range(N): +        if C[i] == 0: +            ind = i +            break +    flag = 0 +    if ind > 0: +        for i in range(ind + 1, N): +            if C[i] > 0: +                flag = 1 +                break +    if flag == 1: +        cnt = 0 +    else: +        C = sorted(list(C.items()), key=lambda x: x[0]) +        cnt = 1 +        for i in range(1, N): +            if C[i][1] == 0: +                break +            c0 = C[i - 1][1] +            c1 = C[i][1] +            cnt = (cnt * (pow(c0, c1))) % p