import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 998244353





def resolve():

    n = int(eval(input()))

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



    tree = [0 for _ in range(max(D) + 1)]

    for i in range(n):

        idx = D[i]

        tree[idx] += 1



    if D[0] != 0 or tree[0] != 1 or 0 in tree:

        print((0))

        exit()



    res = 1

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

        res *= pow(tree[i], tree[i + 1], mod)



    print((res % mod))





if __name__ == '__main__':

    resolve()

import sys



sys.setrecursionlimit(10 ** 7)

f_inf = float('inf')

mod = 998244353





def resolve():

    n = int(eval(input()))

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

    MAX_L = max(D) + 1

    cnt = [0] * MAX_L



    for d in D:

        cnt[d] += 1



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

        print((0))

        exit()



    res = 1

    for i in range(1, MAX_L):

        if cnt[i] == 0:

            print((0))

            break

        res *= pow(cnt[i - 1], cnt[i], mod)

        res %= mod

    else:

        print(res)





if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 998244353


def resolve():
    n = int(eval(input()))
    D = list(map(int, input().split()))
    tree = [0 for _ in range(max(D) + 1)]
    for i in range(n):
        idx = D[i]
        tree[idx] += 1
    if D[0] != 0 or tree[0] != 1 or 0 in tree:
        print((0))
        exit()
    res = 1
    for i in range(len(tree) - 1):
        res *= pow(tree[i], tree[i + 1], mod)
    print((res % mod))


if __name__ == "__main__":
    resolve()

import sys

sys.setrecursionlimit(10**7)
f_inf = float("inf")
mod = 998244353


def resolve():
    n = int(eval(input()))
    D = list(map(int, input().split()))
    MAX_L = max(D) + 1
    cnt = [0] * MAX_L
    for d in D:
        cnt[d] += 1
    if cnt[0] != 1 or D[0] != 0:
        print((0))
        exit()
    res = 1
    for i in range(1, MAX_L):
        if cnt[i] == 0:
            print((0))
            break
        res *= pow(cnt[i - 1], cnt[i], mod)
        res %= mod
    else:
        print(res)


if __name__ == "__main__":
    resolve()

-    tree = [0 for _ in range(max(D) + 1)] -    for i in range(n): -        idx = D[i] -        tree[idx] += 1 -    if D[0] != 0 or tree[0] != 1 or 0 in tree: +    MAX_L = max(D) + 1 +    cnt = [0] * MAX_L +    for d in D: +        cnt[d] += 1 +    if cnt[0] != 1 or D[0] != 0: -    for i in range(len(tree) - 1): -        res *= pow(tree[i], tree[i + 1], mod) -    print((res % mod)) +    for i in range(1, MAX_L): +        if cnt[i] == 0: +            print((0)) +            break +        res *= pow(cnt[i - 1], cnt[i], mod) +        res %= mod +    else: +        print(res)