from itertools import groupby



M = 998244353

n = int(eval(input()))

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

r = 0

if next(a) == 0:

    r = p = 1

    for i, (k, g) in enumerate(groupby(sorted(a)), 1):

        if k != i:

            r = 0

            break

        l = sum(1 for _ in g)

        r = r * pow(p, l, M) % M

        p = l

print(r)

from collections import Counter

 

M = 998244353

n = int(eval(input()))

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

x, c = next(a), Counter(a)

r = 0

if x == c[0] == 0:

    r = p = i = 1

    while c[i]:

        r = r * pow(p, c[i], M) % M

        p = c[i]

        n -= p

        i += 1

print(((r, 0)[n > 1]))

from itertools import groupby

M = 998244353
n = int(eval(input()))
a = list(map(int, input().split()))
r = 0
if next(a) == 0:
    r = p = 1
    for i, (k, g) in enumerate(groupby(sorted(a)), 1):
        if k != i:
            r = 0
            break
        l = sum(1 for _ in g)
        r = r * pow(p, l, M) % M
        p = l
print(r)

from collections import Counter

M = 998244353
n = int(eval(input()))
a = list(map(int, input().split()))
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
    r = p = i = 1
    while c[i]:
        r = r * pow(p, c[i], M) % M
        p = c[i]
        n -= p
        i += 1
print(((r, 0)[n > 1]))

-from itertools import groupby +from collections import Counter +x, c = next(a), Counter(a) -if next(a) == 0: -    r = p = 1 -    for i, (k, g) in enumerate(groupby(sorted(a)), 1): -        if k != i: -            r = 0 -            break -        l = sum(1 for _ in g) -        r = r * pow(p, l, M) % M -        p = l -print(r) +if x == c[0] == 0: +    r = p = i = 1 +    while c[i]: +        r = r * pow(p, c[i], M) % M +        p = c[i] +        n -= p +        i += 1 +print(((r, 0)[n > 1]))