CodeEff/ECCO huggingface dataset:
# Original solution
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    for i in range(max([a, b]), 0, -1):
        if(a % i == 0 and b % i == 0):
            return i
    return 1


def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(line[0], line[1])
        print((str(g) + " " + str(line[0]*line[1]//g)))  # + str(lcm(line[0], line[1]))
    except:
        exit()

# Optimized solution
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(min(line), max(line))
        print((str(g) + " " + str(line[0]*line[1]//g)))  # + str(lcm(line[0], line[1]))
    except:
        exit()
# Original solution
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    for i in range(max([a, b]), a*b + 1):
        if(i % a == 0 and i % b == 0):
            return i
    return a*b


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(min(line), max(line))
        print((str(g) + " " + str(line[0]*line[1]//g)))  # + str(lcm(line[0], line[1]))
    except:
        exit()

# Optimized solution
# This program computes GCD and LCM
# -*- coding: utf-8
import sys


def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


for i in sys.stdin:
    try:
        line = [int(k) for k in i.split(" ")]
        g = gcd(min(line), max(line))
        print((str(g) + " " + str(line[0]*line[1]//g)))
    except:
        exit()
# Original solution
import sys


def gcd(a, b):
    ret = None
    if a <= b:
        large = b
    else:
        large = a
    for i in range(large, 0, -1):
        if i == 0 or i == 1:
            continue
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print("{0} {1}".format(gcd(a, b), lcm(a, b)))


if __name__ == '__main__':
    main()

# Optimized solution
import sys


def gcd(a, b):
    ret = None
    if a <= b:
        large = b
    else:
        large = a
    for i in range(large, 0, -1):
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print("{0} {1}".format(gcd(a, b), lcm(a, b)))


if __name__ == '__main__':
    main()
# Original solution
import sys


def gcd(a, b):
    ret = None
    if a == b:
        return a
    elif a < b:
        large = b
    else:
        large = a
    for i in range(large, 0, -1):
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print("{0} {1}".format(gcd(a, b), lcm(a, b)))


if __name__ == '__main__':
    main()

# Optimized solution
import sys


def gcd(a, b):
    ret = None
    if a > b:
        s = b
    else:
        s = a
    for i in range(s, 0, -1):
        if a % i == 0 and b % i == 0:
            ret = i
            break
    return ret


def lcm(a, b):
    ret = None
    lst = [a, b]
    while True:
        if a == b:
            ret = a
            break
        if a > b:
            b += lst[1]
        else:
            a += lst[0]
    return ret


def main():
    for line in sys.stdin.readlines():
        a, b = [int(n) for n in line.split()]
        print("{0} {1}".format(gcd(a, b), lcm(a, b)))


if __name__ == '__main__':
    main()
# Original solution
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
import sys

for line in sys.stdin:
    small, large = sorted(int(n) for n in line .split())
    for i in range(small, 0, -1):
        if large % i == 0 and small % i == 0:
            gcd = i
            break
    for i in range(2, large + 1):
        if i * small % large == 0:
            lcm = i * small
            break
    print(gcd, lcm)

# Optimized solution
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
import sys

for line in sys.stdin:
    small, large = sorted(int(n) for n in line .split())
    for i in (n for n in range(small, 0, -1) if not small % n):
        if not large % i:
            gcd = i
            break
    for i in range(2, small + 1):
        if not i * large % small:
            lcm = i * large
            break
    print(gcd, lcm)
# Original solution
n = int(eval(input()))
d_l = list(map(int,input().split()))

count_dict = {}
for i in range(n):
    count_dict[i] = 0
for val in d_l:
    count_dict[val] += 1

if d_l[0] != 0 or count_dict[0] != 1:
    ans = 0
else:
    ans = 1

for i in range(1,n):
    ans = ans*(count_dict[i-1]**count_dict[i])
    if ans == 0:
        break

print((ans%998244353))

# Optimized solution
n = int(eval(input()))
d_l = list(map(int,input().split()))

count_dict = {}
for i in range(n):
    count_dict[i] = 0
for val in d_l:
    count_dict[val] += 1

if d_l[0] != 0 or count_dict[0] != 1:
    ans = 0
else:
    ans = 1

for i in range(1,n):
    ans = (ans*(count_dict[i-1]**count_dict[i])) %998244353
    if ans == 0:
        break

print(ans)
# Original solution
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)

N = int(eval(input()))
Ds = list(mapint())
if Ds[0]!=0:
    print((0))
    exit(0)
Ds.sort()
mod = 998244353

from collections import Counter
c = Counter(Ds)
dmax = Ds[-1]


if c[0]>1:
    print((0))
else:
    ans = 1
    for i in range(1, dmax+1):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

# Optimized solution
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return list(map(int, input().split()))
sys.setrecursionlimit(10**9)

N = int(eval(input()))
Ds = list(mapint())
mod = 998244353
from collections import Counter

c = Counter(Ds)
if Ds[0]!=0:
    print((0))
elif c[0]>1:
    print((0))
else:
    ans = 1
    for i in range(1, N):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)
# Original solution
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0]*(max(D)+1)
for i in range(N):
  A[D[i]] += 1
#if D[0] != 0 or not all(D[1:]) or not all(A):
#  print(0)
#  exit()
if D[0] != 0 or not all(D[1:]):
  print((0))
  exit()
for i in range(1, max(D)+1):
#  print(A[i])
  if A[i] == 0:
    print((0))
    exit()
  ans = ans * pow(A[i-1], A[i], mod) % mod
print((ans % mod))

# Optimized solution
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
ans = 1
A = [0]*(max(D)+1)
for i in range(N):
  A[D[i]] += 1
if D[0] != 0 or not all(D[1:]) or not all(A):
  print((0))
  exit()
for i in range(1, max(D)+1):
  ans = ans * pow(A[i-1], A[i], mod) % mod
print((ans % mod))
# Original solution
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))

# Optimized solution
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)
# Original solution
n=int(eval(input()))
d=list(map(int,input().split()))
c=[0]*(n+1)
ans=1
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print((0))
  
else:
  for j in range(1,n):
    if ans==0:
      break
    elif c[j]==0 and c[j+1]==0:
      ans+=0
    else:
      ans*=c[j-1]**c[j]
      
  print((ans%998244353))  
    
  



# Optimized solution
n=int(eval(input()))
d=list(map(int,input().split()))
x=max(d)
li=[0]*(x+1)
for i in range(n):
    li[d[i]]+=1
if d[0]!=0 or li[0]!=1:
    print((0)) 
else:
    ans=1
    for i in range(2,len(li)):
        ans*=pow(li[i-1],li[i],998244353)   
    print((ans%998244353))
# Original solution
mod = 998244353
n = int(eval(input()))
A = [int(x) for x in input().split()]

if A[0] != 0:
    print((0))
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print((0))
    else:
        ans = 1
        for i in range(1,n+1):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print((0))
                break
        else:
            print(ans)



# Optimized solution
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
mod = 998244353


def main():
    N = I()
    A = LI()

    if A[0] != 0:
        return 0

    DistCnt = [0] * (max(A)+1)
    for i in range(N):
        DistCnt[A[i]] += 1

    if DistCnt[0] != 1:
        return 0

    ans = 1
    for i in range(1,len(DistCnt)):
        ans *= pow(DistCnt[i-1],DistCnt[i],mod)
        ans %= mod
    return ans

if __name__ == "__main__":
    print((main()))
# Original solution
import collections
N = int(eval(input()))
D = list(map(int,input().split()))

if D[0] != 0:
    print((0))
    exit()

for i in range(max(D)):
    if i not in D:
        print((0))
        exit()

A = collections.Counter(D)
A = list(A.items())
A.sort()
ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
    if ans >= 998244353:
        ans %= 998244353
print(ans)

# Optimized solution
import collections
N = int(eval(input()))
D = list(map(int,input().split()))

if D[0] != 0 or 0 in D[1:]:
    print((0))
    exit()

A = collections.Counter(D)
A = list(A.items())
A.sort()

if len(A) != max(D) + 1:
    print((0))
    exit()

ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
    if ans >= 998244353:
        ans %= 998244353
print(ans)
# Original solution
import collections
N = int(eval(input()))
D_list = list(map(int, input().split()))
mod = 998244353
ans = 1
count_dir = collections.Counter(D_list)
if max(D_list) >= N:
    ans = 0
else:
    for i in range(max(D_list) + 1):
        if i not in D_list:
            ans = 0
            break
        if i >= 2:
            ans *= count_dir[i-1]**count_dir[i]

if D_list[0] != 0 or count_dir[0] >= 2:
    ans = 0

print((ans%mod))

# Optimized solution
N = int(eval(input()))
D_list = list(map(int, input().split()))
mod = 998244353
ans = 1
count_list = [0]*(max(D_list) + 1)
if max(D_list) >= N:
    ans = 0
else:
    for i in range(len(D_list)):
        count_list[D_list[i]] += 1
    if count_list[1] == 0:
        ans = 0
    else:
        for i in range(2, len(count_list)):
            if count_list[i] == 0:
                ans = 0
                break
            ans *= count_list[i-1]**count_list[i]

if D_list[0] != 0 or count_list[0] >= 2:
    ans = 0

print((ans%mod))
# Original solution
N = int(eval(input()))
D = [int(s) for s in input().split()]

if D[0] != 0:
  print((0))
  exit()
  
max_distance = [i+1 for i in range(max(D))]
stock = 1
for i in max_distance:
  count_1 = D.count(i-1)
  count_2 = D.count(i)
  if count_1 == 0 or count_2 == 0:
    stock = 0
    break
  stock *= count_1**count_2

print((stock%998244353))

# Optimized solution
N = int(eval(input()))
D = [int(s) for s in input().split()]

maximum = max(D)
max_distance = [i+1 for i in range(maximum)]
count_list = [0 for i in range(maximum+1)]
for i in D:
  count_list[i] += 1
if D[0] != 0 or count_list[0] != 1:
  print((0))
  exit()

stock = 1
for i in max_distance:
  count_1 = count_list[i-1]
  count_2 = count_list[i]
  if count_1 == 0 or count_2 == 0:
    stock = 0
    break
  stock *= count_1**count_2

print((stock%998244353))
# Original solution
N = int(eval(input()))
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
mod = 998244353
 
for i, d in enumerate(D):
    if (i == 0) & (d != 0):
        print((0))
        a = 1
        break
    if (i != 0) & (d == 0):
        print((0))
        a = 1
        break
    c[d] += 1


if a == 0:
    for o in range(1, N):
        ans *= c[o]**c[o + 1]

    
    print((ans%mod))


# Optimized solution
N = int(eval(input()))
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
temp = 0
pre = 1
mod = 998244353
c = 1

if D[0] != 0:
    print((0))
    a = 1

if a == 0:
    D = sorted(D)
    for i, d in enumerate(D):
        if i == 0:
            continue
        if d == 0:
            print((0))
            a = 1
            break
        if temp != d:
            if (d - temp) != 1:
                print((0))
                a = 1
                break
            ans *= pre ** c

            temp = d
            pre = c
            c = 1
        else:
            c += 1

        if i == N-1:
            ans *= pre ** c
    if a == 0:
        print((ans%mod))
# Original solution

n = int(eval(input()))
d = list(map(int,input().split()))
db = [0] * (max(d)+1)
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

if (d[0] != 0)|(db[0] != 1):
    print((0))
    exit()

ans = 1

for i in range(len(db)-1):
    ans *= pow(db[i],db[i+1],MOD)

print((ans%MOD))


# Optimized solution
n = int(eval(input()))
d = list(map(int,input().split()))
db = [0] * (max(d)+1)
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

if (d[0] != 0)|(db[0] != 1):
    print((0))
    exit()

ans = 1

for i in range(len(db)-1):
    ans *= db[i]**db[i+1]%MOD

print((ans%MOD))
# Original solution
n = int(eval(input()))
li = list(map(int, input().split()))
li = sorted(li)
count = 1
if not (1 in li and 0 in li):
    count = 0
else:
    for i in range(2,max(li) + 1):
        a = li.count(i-1)
        b = li.count(i)
        count *= a ** b
print((count % 998244353))


# Optimized solution
n = int(eval(input()))
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
for i in li:
    box[i] += 1
count = 1

if len(box) > 2:
    for i in range(1, len(box)-1):
        count *= box[i] ** box[i+1]
        count %= 998244353
else:
    count = 1
    
if box[0] != 1 or li[0] != 0:
    count = 0

print((count % 998244353))
# Original solution
import sys
input=sys.stdin.readline

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

if d[0]!=0:
  print((0))
  exit()
  
kyori=[] #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)

for i in range(0,maxd+1):
  kyori.append(d.count(i))

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print((0))
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)

# Optimized solution
import sys
input=sys.stdin.readline

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

if d[0]!=0:
  print((0))
  exit()

 #1からmaxdまでの距離について、それぞれ何個のdが該当するかメモした配列
maxd=max(d)
kyori=[0]*(maxd+1)

#計算量減らし、、
for i in d:
  kyori[i]+=1

#1個目以外で距離0のやつある場合は停止。
if kyori[0]!=1:
  print((0))
  exit()

ans=1
for i in range(1,maxd):
  temp=kyori[i]**kyori[i+1]
  ans*=temp%998244353
  ans=ans%998244353
print(ans)
# Original solution
from collections import Counter
from functools import reduce
n = int(eval(input()))
d = [int(s) for s in input().split()]
if d[0] != 0:
    print((0))
    quit(0)
c = Counter(d)
if c[0] != 1:
    print((0))
    quit(0)
print((reduce(lambda x, y: x * y, (c[x - 1] for x in d[1:]), 1) % 998244353))



# Optimized solution
from collections import Counter
from functools import reduce
n = int(eval(input()))
d = (int(s) for s in input().split())
if next(d) != 0:
    print((0))
    quit(0)
c = Counter(d)
if c[0] != 0:
    print((0))
    quit(0)
print((reduce(lambda x, y: x * y, (c[k - 1] ** x if k > 1 else 1 for k, x in list(c.items())), 1) % 998244353))
# Original solution
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
counter = [0] * N
for d in D:
    counter[d] += 1

if counter[0] != 1:
    print((0))
    exit()

ans = 1
for d in D[1:]:
    ans *= counter[d-1] % mod
print((ans % mod))

# Optimized solution
N = int(eval(input()))
D = list(map(int, input().split()))
mod = 998244353
counter = [0] * N
for d in D:
    counter[d] += 1

if counter[0] != 1:
    print((0))
    exit()

ans = 1
for d in D[1:]:
    ans = ans * counter[d-1] % mod
print(ans)
# Original solution
N = int(eval(input()))
array = list(map(int, input().split()))
if array[0] != 0:
    print((0))
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print((1))
    exit()
if not (2 in array):
    print((0))
    exit()
if 0 in array[1:]:
    print((0))
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print((0))
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

# Optimized solution
MOD = 998244353
N = int(eval(input()))
D = list(map(int, input().split()))
if D[0] != 0:
    print((0))
    exit()
D_2 = [0]*(max(D)+1)
for i in D:
    D_2[i] += 1
if D_2[0] != 1:
    print((0))
    exit()
ans = 1
for i in range(1,max(D)+1):
    ans *= D_2[i-1]**D_2[i]
    ans %= MOD
print(ans)
# Original solution
n = int(eval(input()))
D = list(map(int, input().split()))


if D[0] != 0:
    ans = 0
else:
    ans = 1
    cnt = 1
    for i in range(max(D)+1):
        ans = ans * (cnt ** D.count(i)) % 998244353
        cnt = D.count(i)

print(ans)


# Optimized solution
n = int(eval(input()))
D = list(map(int, input().split()))


if D[0] != 0 or 0 in D[1:]:
    ans = 0
else:
    num = [0 for i in range(max(D)+1)]
    ans = 1
    cnt = 1
    for i in range(n):
        num[D[i]] += 1
    for i in range(len(num)):
        ans = ans * (cnt ** num[i]) % 998244353
        cnt = num[i]

print(ans)
# Original solution
n=int(eval(input()))
d=list(map(int,input().split()))

mod=998244353
if d[0]!=0:
    print((0))
    exit()
if 0 in d[1:]:
    print((0))
    exit()

ans=1
from collections import Counter
c=Counter(d)

for i in range(1,max(d)+1):
    if i not in list(c.keys()):
        print((0))
        exit()
    ans*=(c[i-1]**c[i])
    ans%=mod

print(ans)


# Optimized solution
n=int(eval(input()))
d=list(map(int,input().split()))

mod=998244353
if d[0]!=0:
    print((0))
    exit()
if 0 in d[1:]:
    print((0))
    exit()

ans=1
from collections import Counter
c=Counter(d)

for i in range(1,max(d)+1):
    if not i in c:
        print((0))
        exit()
    ans*=(c[i-1]**c[i])
    ans%=mod

print(ans)
# Original solution
from collections import Counter
n = int(eval(input()))
d = list(map(int, input().split()))

if d[0] != 0:
    print((0))
    exit()

cnt = Counter(d)

if cnt[0] != 1:
    print((0))
    exit()

ans = 1
for i in d:
    if i != 0:
        ans *= cnt[i-1] % 998244353
print((ans % 998244353))

# Optimized solution
from collections import Counter
n = int(eval(input()))
d = list(map(int, input().split()))

if d[0] != 0:
    print((0))
    exit()

cnt = Counter(d)

if cnt[0] != 1:
    print((0))
    exit()

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)
# Original solution
if __name__ == "__main__":
    mod = 998244353

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

    if d[0] > 0:
        print('0')
        exit()

    d.sort()
    d.pop(0)
    if d[0] == 0:
        print('0')
        exit()

    tmp = 1
    ans = 1
    max_num = max(d)
    for i in range(1, max_num+1):
        if i+1 in d:
            count = d.index(i+1)
        elif i+1 == max_num+1:
            count = len(d)
        else:
            print('0')
            exit()
        ans *= tmp ** count
        ans %= mod
        tmp = count
        d = d[count:]

    print(ans)


# Optimized solution
if __name__ == "__main__":
    mod = 998244353

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

    if d[0] > 0:
        print('0')
        exit()

    if len(d) == 1:
        print('1')
        exit()

    d.sort()
    d.pop(0)
    if d[0] == 0:
        print('0')
        exit()

    tmp = 1
    ans = 1
    max_num = max(d)
    dic = dict()
    for i in range(n-1):
        if d[i] in dic:
            dic[d[i]] += 1
        else:
            dic[d[i]] = 1

    for i in range(1, max_num+1):
        if i in dic:
            count = dic[i]
        else:
            print('0')
            exit()
        if count == 0:
            print('0')
            exit()
        ans *= tmp ** count
        ans %= mod
        tmp = count

    print(ans)
# Original solution
# 最初dは与えられる距離だと思ってて「サンプルケース1は3じゃね？」とか思ってて2時間経過した
# 落ち着いて読んだら最小の辺の数だった

from collections import Counter

n = int(eval(input()))
arr = list(map(int, input().split()))
if arr[0] != 0:
    print((0))
    exit()
arr = sorted(list(Counter(arr).items()), key=lambda x: x[0])
if arr[0][1] > 1:
    print((0))
    exit()

mod = 998244353
ans = 1
tmp = 1
for i in range(1, len(arr)):
    if arr[i][0] != i:
        print((0))
        exit()
    ans *= pow(tmp, arr[i][1])
    ans %= mod
    tmp = arr[i][1]

print(ans)


# Optimized solution
n = int(eval(input()))
d = {}
mod = 998244353
max_v = 0
lis = list(map(int, input().split()))

# 先頭はかならず0
if lis[0] != 0:
    print((0))
    exit()

for v in lis:
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)

# 0はひとつだけ
if 0 not in d or d[0] > 1:
    print((0))
    exit()

ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
print(ans)
# Original solution
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()


# Optimized solution
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()