MOD = 998244353



def beki(x, n):

  if n == 0:

    return 1

  if n % 2 == 0:

    return beki(x * x % MOD, n // 2) % MOD

  else:

    return x * beki(x, n - 1) % MOD





N = int(eval(input()))

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

D = sorted(Orig)



ans = 1

cnt = 1

precnt = 1



if Orig[0] != 0:

    ans = 0

if N >= 2 and D[1] == 0:

    ans = 0



for i in range(N-1):

    if D[i] == D[i+1]:

        cnt += 1



    elif D[i] + 1 != D[i+1]:

        ans = 0

        break



    else:

        ans *= beki(precnt, cnt)

        ans %= MOD

        precnt = cnt

        cnt = 1

        if (i == N-1):

            break

else:

    ans *= beki(precnt, cnt)

    ans %= MOD



print(ans)



def mod_pow(x, n, MOD):

    if n == 0:

        return 1

    if n % 2 == 0:

        result = mod_pow(x * x, n // 2, MOD)

        return result % MOD

    else:

        result = x * mod_pow(x, n - 1, MOD)

        return result % MOD



from collections import Counter        



MOD = 998244353

N = int(eval(input()))

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

max_num = max(D)



count = Counter(D)

ans = 1



if D[0] != 0:

    print((0))

    exit()



if count[0] != 1:

    print((0))

    exit()



for i in range(max_num):



    ans *= mod_pow(count[i], count[i+1], MOD)

    ans %= MOD



print(ans)
MOD = 998244353


def beki(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return beki(x * x % MOD, n // 2) % MOD
    else:
        return x * beki(x, n - 1) % MOD


N = int(eval(input()))
Orig = list(map(int, input().split()))
D = sorted(Orig)
ans = 1
cnt = 1
precnt = 1
if Orig[0] != 0:
    ans = 0
if N >= 2 and D[1] == 0:
    ans = 0
for i in range(N - 1):
    if D[i] == D[i + 1]:
        cnt += 1
    elif D[i] + 1 != D[i + 1]:
        ans = 0
        break
    else:
        ans *= beki(precnt, cnt)
        ans %= MOD
        precnt = cnt
        cnt = 1
        if i == N - 1:
            break
else:
    ans *= beki(precnt, cnt)
    ans %= MOD
print(ans)

def mod_pow(x, n, MOD):
    if n == 0:
        return 1
    if n % 2 == 0:
        result = mod_pow(x * x, n // 2, MOD)
        return result % MOD
    else:
        result = x * mod_pow(x, n - 1, MOD)
        return result % MOD


from collections import Counter

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

-MOD = 998244353 - - -def beki(x, n): +def mod_pow(x, n, MOD): -        return beki(x * x % MOD, n // 2) % MOD +        result = mod_pow(x * x, n // 2, MOD) +        return result % MOD -        return x * beki(x, n - 1) % MOD +        result = x * mod_pow(x, n - 1, MOD) +        return result % MOD +from collections import Counter + +MOD = 998244353 -Orig = list(map(int, input().split())) -D = sorted(Orig) +D = list(map(int, input().split())) +max_num = max(D) +count = Counter(D) -cnt = 1 -precnt = 1 -if Orig[0] != 0: -    ans = 0 -if N >= 2 and D[1] == 0: -    ans = 0 -for i in range(N - 1): -    if D[i] == D[i + 1]: -        cnt += 1 -    elif D[i] + 1 != D[i + 1]: -        ans = 0 -        break -    else: -        ans *= beki(precnt, cnt) -        ans %= MOD -        precnt = cnt -        cnt = 1 -        if i == N - 1: -            break -else: -    ans *= beki(precnt, cnt) +if D[0] != 0: +    print((0)) +    exit() +if count[0] != 1: +    print((0)) +    exit() +for i in range(max_num): +    ans *= mod_pow(count[i], count[i + 1], MOD)