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 = 1

  for i in range(1, n + 1):

    x = c[i]

    if x == 0:

      break

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

    p = x; n -= p

print(((r, 0)[n > 1]))
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 = 1

  try:

    for i in range(1, n + 1):

      x = c.get(i)

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

      p = x; n -= p

  except:

    pass

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

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 = 1
    for i in range(1, n + 1):
        x = c[i]
        if x == 0:
            break
        r = r * pow(p, x, M) % M
        p = x
        n -= p
print(((r, 0)[n > 1]))

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 = 1
    try:
        for i in range(1, n + 1):
            x = c.get(i)
            r = r * pow(p, x, M) % M
            p = x
            n -= p
    except:
        pass
print(((r, 0)[n > 1]))

-    for i in range(1, n + 1): -        x = c[i] -        if x == 0: -            break -        r = r * pow(p, x, M) % M -        p = x -        n -= p +    try: +        for i in range(1, n + 1): +            x = c.get(i) +            r = r * pow(p, x, M) % M +            p = x +            n -= p +    except: +        pass