from collections import Counter



n=int(eval(input()))

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

if d[0]!=0:

    print((0))

    exit()

c=Counter(d)

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

if c[0]!=(0,1):

    print((0))

    exit()

ans=1

check=1

for i in range(1,len(c)):

    if c[i][0]!=check:

        print((0))

        exit()

    check+=1

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

    ans%=998244353

print((ans%998244353))
from sys import stdin

nii=lambda:list(map(int,stdin.readline().split()))

lnii=lambda:list(map(int,stdin.readline().split()))

from collections import Counter



n=int(eval(input()))

d=lnii()



mod=998244353



c=Counter(d)

max_key=max(d)



if d[0]!=0 or c[0]!=1:

  print((0))

  exit()



ans=1

patterns=1

for i in range(max_key+1):

  p_num=c[i]

  ans*=patterns**p_num

  ans%=mod

  patterns=p_num



print(ans)
from collections import Counter

n = int(eval(input()))
d = list(map(int, input().split()))
if d[0] != 0:
    print((0))
    exit()
c = Counter(d)
c = sorted(list(c.items()), key=lambda x: x[0])
if c[0] != (0, 1):
    print((0))
    exit()
ans = 1
check = 1
for i in range(1, len(c)):
    if c[i][0] != check:
        print((0))
        exit()
    check += 1
    ans *= c[i - 1][1] ** c[i][1]
    ans %= 998244353
print((ans % 998244353))

from sys import stdin

nii = lambda: list(map(int, stdin.readline().split()))
lnii = lambda: list(map(int, stdin.readline().split()))
from collections import Counter

n = int(eval(input()))
d = lnii()
mod = 998244353
c = Counter(d)
max_key = max(d)
if d[0] != 0 or c[0] != 1:
    print((0))
    exit()
ans = 1
patterns = 1
for i in range(max_key + 1):
    p_num = c[i]
    ans *= patterns**p_num
    ans %= mod
    patterns = p_num
print(ans)

+from sys import stdin + +nii = lambda: list(map(int, stdin.readline().split())) +lnii = lambda: list(map(int, stdin.readline().split())) -d = list(map(int, input().split())) -if d[0] != 0: -    print((0)) -    exit() +d = lnii() +mod = 998244353 -c = sorted(list(c.items()), key=lambda x: x[0]) -if c[0] != (0, 1): +max_key = max(d) +if d[0] != 0 or c[0] != 1: -check = 1 -for i in range(1, len(c)): -    if c[i][0] != check: -        print((0)) -        exit() -    check += 1 -    ans *= c[i - 1][1] ** c[i][1] -    ans %= 998244353 -print((ans % 998244353)) +patterns = 1 +for i in range(max_key + 1): +    p_num = c[i] +    ans *= patterns**p_num +    ans %= mod +    patterns = p_num +print(ans)