N = int(eval(input()))

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

if array[0] != 0:

    print((0))

    exit()

array.sort()

if 1 in array and len(set(array[1:])) == 1:

    print((1))

    exit()

if not (2 in array):

    print((0))

    exit()

if 0 in array[1:]:

    print((0))

    exit()

index = array.index(2)

count = 1

count_old = array.count(1)

ans = 1

first = array[index]

for i in range(index,N-1):

    if first != array[i+1]:

        if first != array[i+1] - 1:

            print((0))

            exit()

        ans *= count_old ** count

        count_old = count

        count = 1

    else:

        count += 1

    first = array[i+1]

    ans %= 998244353

ans *= count_old ** count

ans %= 998244353

print(ans)
MOD = 998244353

N = int(eval(input()))

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

if D[0] != 0:

    print((0))

    exit()

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

for i in D:

    D_2[i] += 1

if D_2[0] != 1:

    print((0))

    exit()

ans = 1

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

    ans *= D_2[i-1]**D_2[i]

    ans %= MOD

print(ans)

N = int(eval(input()))
array = list(map(int, input().split()))
if array[0] != 0:
    print((0))
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print((1))
    exit()
if not (2 in array):
    print((0))
    exit()
if 0 in array[1:]:
    print((0))
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index, N - 1):
    if first != array[i + 1]:
        if first != array[i + 1] - 1:
            print((0))
            exit()
        ans *= count_old**count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i + 1]
    ans %= 998244353
ans *= count_old**count
ans %= 998244353
print(ans)

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

+MOD = 998244353 -array = list(map(int, input().split())) -if array[0] != 0: +D = list(map(int, input().split())) +if D[0] != 0: -array.sort() -if 1 in array and len(set(array[1:])) == 1: -    print((1)) -    exit() -if not (2 in array): +D_2 = [0] * (max(D) + 1) +for i in D: +    D_2[i] += 1 +if D_2[0] != 1: -if 0 in array[1:]: -    print((0)) -    exit() -index = array.index(2) -count = 1 -count_old = array.count(1) -first = array[index] -for i in range(index, N - 1): -    if first != array[i + 1]: -        if first != array[i + 1] - 1: -            print((0)) -            exit() -        ans *= count_old**count -        count_old = count -        count = 1 -    else: -        count += 1 -    first = array[i + 1] -    ans %= 998244353 -ans *= count_old**count -ans %= 998244353 +for i in range(1, max(D) + 1): +    ans *= D_2[i - 1] ** D_2[i] +    ans %= MOD