from collections import Counter



N = int(eval(input()))

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

MOD = 998244353



# 条件をみたす木が存在するには D1 = 0 が必要

if D[0] != 0:

  print((0))

  exit()

# 0 == 1

ctr = Counter(D)

if ctr[0] != 1:

  print((0))

  exit()

  

ans = 1

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

  ans *= pow(ctr[i], ctr[i+1], MOD)

  ans %= MOD

print(ans)  


from collections import Counter

def resolve():

    MOD = 998244353

    N = int(eval(input()))

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



    if D[0] != 0:

        print((0))

        return



    CNT = Counter(D)

    if CNT[0] > 1:  # 距離0は1個

        print((0))

        return



    ans = 1

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

        ans *= pow(CNT[i - 1], CNT[i], MOD)

        ans %= MOD



    print(ans)





if __name__ == "__main__":

    resolve()

from collections import Counter

N = int(eval(input()))
D = list(map(int, input().split()))
MOD = 998244353
# 条件をみたす木が存在するには D1 = 0 が必要
if D[0] != 0:
    print((0))
    exit()
# 0 == 1
ctr = Counter(D)
if ctr[0] != 1:
    print((0))
    exit()
ans = 1
for i in range(len(ctr) - 1):
    ans *= pow(ctr[i], ctr[i + 1], MOD)
    ans %= MOD
print(ans)

from collections import Counter


def resolve():
    MOD = 998244353
    N = int(eval(input()))
    D = list(map(int, input().split()))
    if D[0] != 0:
        print((0))
        return
    CNT = Counter(D)
    if CNT[0] > 1:  # 距離0は1個
        print((0))
        return
    ans = 1
    for i in range(1, max(D) + 1):
        ans *= pow(CNT[i - 1], CNT[i], MOD)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    resolve()

-N = int(eval(input())) -D = list(map(int, input().split())) -MOD = 998244353 -# 条件をみたす木が存在するには D1 = 0 が必要 -if D[0] != 0: -    print((0)) -    exit() -# 0 == 1 -ctr = Counter(D) -if ctr[0] != 1: -    print((0)) -    exit() -ans = 1 -for i in range(len(ctr) - 1): -    ans *= pow(ctr[i], ctr[i + 1], MOD) -    ans %= MOD -print(ans) + +def resolve(): +    MOD = 998244353 +    N = int(eval(input())) +    D = list(map(int, input().split())) +    if D[0] != 0: +        print((0)) +        return +    CNT = Counter(D) +    if CNT[0] > 1:  # 距離0は1個 +        print((0)) +        return +    ans = 1 +    for i in range(1, max(D) + 1): +        ans *= pow(CNT[i - 1], CNT[i], MOD) +        ans %= MOD +    print(ans) + + +if __name__ == "__main__": +    resolve()