Problem:
 Score : 300 points    Problem Statement Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353 , of trees with N vertices numbered 1 to N that satisfy the following condition:   For every integer i from 1 to N , the distance between Vertex 1 and Vertex i is D_i .       Notes  A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.  Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.       Constraints  1 \leq N \leq 10^5  0 \leq D_i \leq N-1         Input Input is given from Standard Input in the following format:  N  D_1  D_2  ...  D_N       Output Print the answer.        Sample Input 1 4
0 1 1 2      Sample Output 1 2  For example, a tree with edges (1,2) , (1,3) , and (2,4) satisfies the condition.       Sample Input 2 4
1 1 1 1      Sample Output 2 0       Sample Input 3 7
0 3 2 1 2 2 1      Sample Output 3 24

Solution (Python):
n = int(input())

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

def f(n,ls):
  if not ls[0] == 0: return 0
  ls = sorted(ls)
  mod = 998244353
  arr = [0]*(ls[-1]+1)
  
  for i in range(n):
    arr[ls[i]] += 1
  if arr[0] >1: return 0
  ans = 1
  for i in range(1,len(arr)):
    
    if arr[i] == 0:
      return 0
    ans *= arr[i-1]**arr[i]
  return ans%mod

print(f(n,ls))

Solution (Python):
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True 
BIG = 999999999
R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
d = inl()

if d[0]!=0:
    print(0)
    exit()
a = [0]*n
for i in range(n):
    a[d[i]] += 1
if a[0]>1:
    print(0)
    exit()




p = 1
t = -1
for i in range(1,n):
    if a[i]==0:
        t = i
        break
    p = (p * (a[i-1]**a[i])) % R
if t>=0:
  for i in range(t+1,n):
    if a[i]>0:
        print(0)
        exit()
print(p)

Solution (Python):
n = int(input())
d = [int(i) for i in input().split()]
a = [0] * n
k = 0
for i in d:
    a[i] += 1
    k=max(k,i)
if d[0] != 0:
    print(0)
elif a[0] != 1:
    print(0)
else:
    j = 1
    for i in range(k):
        j *= a[i] ** a[i + 1]
        j %= 998244353
    print(j)

Solution (Python):
n = int(input())
d_list = [int(i) for i in input().split()]
R_max = max(d_list)+1
R = [0] * R_max
ans = 1
if d_list[0] != 0:
  print(0)
  exit()
  
for di in d_list:
  R[di] += 1
  
if R[0] != 1:
  print(0)
  exit()
  
for i in range(1, R_max):
  ans *= R[i-1]**R[i]%998244353
print(ans%998244353)

Solution (Python):
from collections import Counter

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

num = 998244353

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

if D.count(0) != 1:
    print(0)
    exit()


D_cnt = dict(Counter(D))
D_list = list(D_cnt)
D_list.sort()
ans = 1


if D_list != list(range(len(D_list))):
    print(0)
    exit()

for i in range(1, len(D_list) - 1):
    n = D_cnt[i]
    m = D_cnt[i + 1]

    ans *= (n ** m)
    ans %= num
print(ans % num)

Solution (Python):




 
from collections import* 
from fractions import gcd
from functools import* 
from itertools import* 
from operator import mul,itemgetter
from bisect import* 
from heapq import* 
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)


mod=998244353

def main():
    n,*a=map(int,open(0).read().split())
    if a[0]!=0:
        print(0)
        exit()
    for i in a[1:]:
        if i==0:
            print(0)
            exit()
    
    ans=1
    a=Counter(a)
    for i in range(len(a)-1):
        ans*=pow(a[i],a[i+1],mod)%mod
    print(ans%mod)

    
    
if __name__ == '__main__':
    main()

Solution (Python):
mod = 998244353
N = int(input())
D = list(map(int,input().split()))
D_max = max(D)
C = [0]*(D_max + 1)
for i in range(len(D)):
    C[D[i]] += 1
tmp = 1
for i in range(len(C)-1):
    tmp = tmp * (C[i]**C[i+1]) % mod
if D[0] != 0 or C[0] > 1:
    tmp = 0
print(tmp)

Solution (Python):
import collections
mod=998244353
ans=1
n=int(input())
d=list(map(int,input().split()))
c=collections.Counter(d)
num=[]
for j in range(len(c)):
  num.append(c[j])
if d[0]!=0 or num[0]!=1:
  print(0)
else:
  for i in range(1,len(num)-1):
    ans*=(num[i]**num[i+1])%mod
  print(ans%mod)

Solution (Python):
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]
mod = 998244353

def solve() :
    c = Counter(D)
            
    if c[0] != 1 or D[0] != 0 :
        return 0
        
    ret = 1
    for i in range(1, max(c) + 1) :        
        ret = ret * pow(c[i-1], c[i], mod) % mod
    
    return ret
        
print(solve())

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i != 1 and i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)

Solution (Python):
import collections

mod = 998244353

n = int(input())
d = list(map(int, input().split()))
dc = collections.Counter(d).most_common()
dc = sorted(dc)
if d[0] == 0 and dc[0][1] == 1:
    count = 0
    ans = 1
    last = 1
    for i in dc:
        if i[0] == count:
            ans = ans * (last ** i[1]) % mod
            last = i[1]
            count += 1
        else:
            print(0)
            exit()
    print(ans % mod)
else:
    print(0)

Solution (Python):
from collections import Counter

n = int(raw_input())
d = map(int, raw_input().split())
count_d = Counter(d)

if count_d[0] != 1 or d[0] != 0:
    print 0
else:
    pre_i = 0
    result = 1
    pre_nodes = 1
    for i, num in count_d.items()[1:]:
        if i != pre_i + 1:
            result = 0
            break
        result *= (pre_nodes ** num)
        pre_i = i
        pre_nodes = num
    print result % 998244353

Solution (Python):
N=int(input())
D=list(map(int,input().split()))
if D[0] >0:
  print(0)
  exit()
X=[0]*N
for d in D[1:]:
  X[d-1]+=1
ans=1
i=1
while X[i]!=0:
  ans*=X[i-1]**X[i]
  i+=1
while i<N:
  if X[i]!=0:
    ans=0
    break
  i+=1
print(ans%998244353)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
dic = {}
if d[0]:
    print(0)
else:
    for di in d:
        if di not in dic:
            dic[di] = 0
        dic[di] += 1
    dists = list(dic.keys())
    dists.sort()
    ans = 1
    l = [dic[dist] for dist in dists]
    if l[0] != 1:
        print(0)
    elif dists != list(range(len(dists))):
        print(0)
    else:
        for l1, l2 in zip(l, l[1:]):
            ans = ans * (l1 ** l2) % mod
        print(ans)

Solution (Python):
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 998244353
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		if (a [ 0 ] != 0):
			print (0)
			continue
		a.sort()
		if(a[0]!=0):
			print(0)
		else:
			ox=[]
			cc=1
			las=a[0]
			for i in range(1,n):
				if(las==a[i]):
					cc+=1
				else:
					ox.append((las,cc))
					cc=1
					las=a[i]
			ox.append ((las, cc))
			if(ox[0][1]!=1):
				print(0)
				continue
			last=ox[0][1]
			next=ox[0][0]+1
			ans=1
			for i in range(1,len(ox)):
				if(next!=ox[i][0]):
					ans=0
				ans=(ans*pow(last,ox[i][1],mm))%mm
				last=ox[i][1]
				next+=1
			print(ans)










if __name__ == "__main__":
	solve ()

Solution (Python):
MOD = 998244353
import collections
N = int(input())
D = list(map(int, input().split()))
mx = max(D)
c = collections.Counter(D)

if D[0] == 0 and c[0] == 1:
    ans = 1
    for i in range(1, mx+1):
        if i not in c:
            ans = 0
            break
        else:
            ans *= (c[i-1] ** c[i]) % MOD
            ans %= MOD
else:
    ans = 0

print(ans)

Solution (Python):

import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n = II()
    d = LMIIS()

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

    d.sort()

    a = 1

    c = 0
    old_c = 1
    ans = 1
    for i in range(1, n):
        if d[i] == a:
            c += 1
        elif d[i] == a+1 and c > 0:
            for j in range(c):
                ans = ans * old_c % 998244353
            a += 1
            old_c = c
            c = 1
        else:
            print(0)
            exit()

    if c > 0:
        for j in range(c):
            ans = ans * old_c % 998244353
    print(ans)









if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')


def A():
    n = II()
    n -= 1
    print(n // 2)
    return


def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
        ans %= mod
    print(ans)
    return


def C():
    return


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == '__main__':
    B()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    mod = 998244353
    N = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0 or D.count(0) != 1:
        print(0)
        return
    DD = dict()
    for d in D:
        if d in DD:
            DD[d] += 1
        else:
            DD[d] = 1
    li = sorted(DD.items(), key=lambda x:x[0])
    ans = 1
    x = 0
    pre_v = 1

    for k, v in li:
        if k != x:
            print(0)
            return
        ans *= (pre_v**v)
        ans = ans % mod

        pre_v = v
        x += 1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
u = 998244353

if A[0]!=0:
    print(0)
    exit()
dp = {}

for i in range(1,N):
    d = A[i]
    if d==0:
        print(0)
        exit()
    if d in dp:
        dp[d] +=1
    else:
        dp[d] = 1

M = max(A)
ans = 1
pre = 1
for i in range(1,M+1):
    if not i in dp:
        print(0)
        exit()
    k = dp[i]
    now = pre**k
    ans *= now
    ans %= u
    pre = k
print(ans)

Solution (Python):
CONST = 998244353
n = int(input())
d = list(map(int, input().split()))
l = [0 for i in range(n)]
max_d = max(d)
for i in d:
  l[i] += 1
ans = 1
cnt = 0
prev = 1
if d[0] != 0:
  print(0)
elif l[0] != 1:
  print(0)
else:
  for i in range(max_d+1):
    cnt = l[i]
    ans *= prev**cnt%CONST
    prev = cnt
  print(ans%CONST)

Solution (Python):
import sys
input = sys.stdin.readline
from collections import Counter

mod = 998244353

def power_func(a,n,mod):
    bi=str(format(n,"b"))
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

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

A = Counter(D)
B = sorted(A.items())

if D[0] != 0:
    print(0)
else:
    ans = 1
    for i, (k, num) in enumerate(B):
        if i == 0:
            if num != 1:
                ans = 0
                break
            pre = 0
            continue
        if k != pre + 1:
            ans = 0
            break
        if k == 1:
            pre = 1
            p = num
            continue
        ans = ans * power_func(p, num, mod) % mod
        p = num
        pre = k
    
    print(ans)

Solution (Python):
import collections

N = int(input())
D = list(map(int, input().split()))
mod = 998244353


if D[0] != 0 :
  print(0)
else :
  D_dict  = collections.Counter(D)
  if D_dict[0] > 1 :
    print(0)
    exit()
  result = 1
  for i in range(1, len(D_dict)) :
    if D_dict[i] == 0 :
      print(0)
      exit()
    else :
      result *= D_dict[i-1]**D_dict[i]
      result = result % mod

  print(result)

Solution (Python):
import sys
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
    print(0)
    sys.exit()
d.sort()
if d[1]==0:
    print(0)
    sys.exit()
else:
    lst=[0]*(n+1)
    for i in range(0,n):
        lst[d[i]]+=1
    ans=1
    for i in range(1,d[-1]+1):
        ans=(ans*pow(lst[i-1],lst[i],mod))%mod
    print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

mod = 998244353
ans = 1

if d[0] != 0 or d.count(0) > 1:
    print(0)
    exit()

d.sort()

for i in range(n-1):
    if d[i+1] - d[i] > 1:
        print(0)
        exit()

count = 1
count2 = 0
li = [1]

for i in range(1,n):
    if count == d[i]:
        count2 += 1
    else:
        li.append(count2)
        count += 1
        count2 = 1

if count2 != 1:
    li.append(count2)
else:
    if count == d[-1]:
        li.append(1)
    else:
        print(0)
        exit()

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

print(ans)

Solution (Python):
import collections

MOD=998244353
N=int(input())
D=list(map(int, input().split()))
c=collections.Counter(D)
counter=sorted(c.items(), key=lambda x:x[0])
if D[0]!=0 or counter[0][1]>1:
  print(0)
else:
  flag=True
  pre=0
  for i in range(1, len(counter)):
    if pre+1!=counter[i][0]:
      flag=False
      break
    pre+=1
  if not flag:
    print(0)
  else:
    ans=1
    for i in range(2, len(counter)):
      for j in range(counter[i][1]):
        ans=(ans*counter[i-1][1])%MOD
      
    print(ans)

Solution (Python):



from collections import Counter,deque


from sys import stdin,setrecursionlimit







setrecursionlimit(10**6)
input=stdin.readline

n=int(input())
d=[int(i) for i in input().split()]
m=max(d)
if d[0]!=0:
    print(0)
    exit()
dst=[0]*(m+1)
ans=1
for i in d: dst[i]+=1

if dst[0]>1:
    print(0)
    exit()
for i in range(2,m+1):
    if dst[i]==0:
        print(0)
        exit()
    ans*=dst[i-1]**dst[i]
print(ans%998244353)

Solution (Python):
n = int(input())
d_array = list(map(int, input().split()))
if d_array[0] != 0:
    print(0)
else:
    count = [0 for _ in range(n)]
    count[0] = 1
    for d in d_array[1:]:
        count[d] += 1
    i = 1
    node = 1
    ans = 1
    while node < n and i < n:
        if count[i] == 0:
            ans = 0
            break
        ans *= count[i - 1] ** count[i]
        ans %= 998244353
        node += count[i]
        i += 1
    print(ans)

Solution (Python):
n=int(input())
t=tuple(map(int,input().split()))
while True:
  if t[0]!=0:
    print(0)
    break
  m=max(t)
  a=[0]*(m+1)
  for i in range(n):
    a[t[i]]+=1
  a=tuple(a)
  if a[0]!=1:
    print(0)
    break
  s=1
  for i in range(m):
    s=(s*(a[i]**a[i+1]))%998244353
  print(s)
  break

Solution (Python):
import collections
import sys

n = int(input())
nums = list(map(int, input().split()))

max_nums = max(nums)
cnt_list = collections.Counter(nums)


ans = 1
if cnt_list[0] == 1 and nums[0] == 0:
	for i in range(1, max_nums + 1):
		if cnt_list[i] == 0:
			print(0)
			sys.exit()
		else:
			ans *= (cnt_list[i - 1] ** cnt_list[i]) % 998244353
			
	print(ans % 998244353)

else:
	print(0)

Solution (Python):
import sys; readline = sys.stdin.readline
from collections import deque

from collections import Counter
P = 998244353
N = int(readline())
D = list(map(int, readline().split()))

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

def mod_pow(a, b):
    ret = 1
    for i in range(b):
        ret = ret * a % P
    return ret

if D[0] != 0 or c[0][1] != 1:
    print(0)
else:
    ans = 1
    for i in range(1, len(c)):
        if c[i - 1][0] != c[i][0] - 1:
            print(0)
            exit(0)
        ans = ans * mod_pow(c[i-1][1], c[i][1]) % P
    print(ans)

Solution (Python):
n = int(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)

Solution (Python):
N = int(input())
D = [int(d) for d in input().split()]
D0 = D[0]
D1 = sorted(D[1:])

def calc(D1):
    r = 1
    m = {0:1}
    for d in D1:
        if d-1 in m:
            r = r * m[d-1] % 998244353
            if d in m:
                m[d] = m[d] + 1
            else:
                m[d] = 1
        else:
            return(0)
    return(r)

if D0 != 0:
    print(0)
else:
    print(calc(D1) % 998244353)

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
D = list(map(int,input().split()))
dmax = max(D)
M = 998244353

if D[0]!=0:
	ans = 0
else:
	D = Counter(D)

	if D[0]!=1:
		ans = 0
	else:
		ans = 1
		for i in range(1,dmax+1):
			if D[i]==0:
				ans = 0
				break
			ans *= D[i-1]**D[i]
			ans = ans%M

print(ans)

Solution (Python):
from collections import Counter


MOD = 998244353


def power(a, n, p=MOD):
    res = 1
    for _ in range(n):
        res *= a
        res %= p
    return res


n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    exit(0)

d = Counter(sorted(d))
if d[0] > 1:
    print(0)
    exit(0)

d = sorted(d.items())
prev_index = -1
prev_count = 1

ans = 1
for k, v in d:
    if k != prev_index+1:
        print(0)
        exit(0)
    ans *= power(prev_count, v)
    ans %= MOD
    prev_index = k
    prev_count = v
print(ans)

Solution (Python):
from collections import Counter

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

mod = 998244353
  

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

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

keys = sorted(dic.keys())
prev_num = 0
prev_count = 1
ans = 1
for num in keys:
    if num == 0:
        continue

    if num - prev_num != 1:
        print(0)
        exit()

    count = dic[num]
    ans *= prev_count ** count
    ans %= mod
    prev_num = num
    prev_count = count

print(ans)

Solution (Python):
N = int(input())
D = [int(x) for x in input().split()]

if D[0] != 0:
  print(0)
else:
  flag = True
  D.sort()
  dic = {}
  prev = -1
  for i in D:
    if i not in dic:
      dic[i] = 1
      if(i != prev + 1):
        flag = False
      else:
        prev = i
    else:
      dic[i] += 1
  prev = -1
  cnt = 1
  if dic[0] != 1:
    flag = False
  if flag:
    for k in dic:
      if k > 0:
        t = 1
        for j in range(dic[k]):
          t *= dic[k - 1]
        cnt *= t
  if flag:
    print(cnt % 998244353)
  else:
    print(0)

Solution (Python):
N = int(input().strip())
D = list(map(int, input().strip().split()))
tmpD = D[1:]
tmpD = sorted(tmpD)





if D[0] != 0 or tmpD[0] == 0:
    print(0)
else:
    ans = 1
    max_depth = max(tmpD)
    count = [0] * (max_depth+1)
    for num in tmpD:
        count[num]+=1
    for i in range(1, max_depth):
        ans *= (count[i]**count[i+1])
        ans %= 998244353
    print(ans)

Solution (Python):
n = int(input())
d = list(map(int,input().split()))
mod = 998244353

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

if n == 1:
        print(1)
        exit()

if n == 2:
    if d[1] == 1:
        print(1)
        exit()
    else:
        print(0)
        exit()


a = [0]*n

while d:
    s = d.pop()
    a[s] += 1

if a[0] >= 2:
    print(0)
    exit()

ans = 1

for i in range(n-1):
        ans *= a[i]**a[i+1]
        ans %= mod

print(ans % mod)

Solution (Python):


import sys
import math
import collections



n=int(input())

tmp = input().split()
d = list(map(lambda a: int(a), tmp))

max=0
numlist={}
for i in range(0,n):
	if(d[i]>max):
		max=d[i]
	if(d[i] in numlist):
		numlist[d[i]]+=1
	else:
		numlist[d[i]]=1


if(d[0]!=0):
	print(0)
	sys.exit()
for i in range(max):
	if not(i in numlist):
		print(0)
		sys.exit()
if(numlist[0]!=1):
	print(0)
	sys.exit()


ans=1
for i in range(1,max):
	
	ans=ans*numlist[i]**numlist[i+1]

print(ans % 998244353)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    exit()
D.sort()
d = {}
for i in range(D[-1] + 1):
    d[i] = 0

for i in D:
    d[i] += 1

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

for i in range(1, D[-1] + 1):
    if d[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(2, D[-1] + 1):
    ans *= (d[i-1]**d[i]) % 998244353
    ans = ans % 998244353
print(ans)

Solution (Python):
from collections import Counter

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

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

ans = 1
idx = 1
C = sorted(Counter(D[1:]).items())
for k, v in C:
    if k != idx:
        print(0)
        exit()
    if k == 1:
        _v = v
    else:
        ans = ans * _v ** v % 998244353
        _v = v
    idx += 1
print(ans)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
if d[0] != 0:
    print(0)
    quit()
d.sort()
d = list(Counter(d).items())
n = len(d)
if d[0][1] > 1:
    print(0)
    quit()
ans = 1
for i in range(1,n):
    j,k = d[i]
    l,m = d[i-1]
    if j != l+1:
        print(0)
        quit()
    ans *= m**k
    ans %= mod
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:print(0)
else:
  a.sort()
  mod=998244353
  if n==1:print(1)
  elif a[1]==0:print(0)
  else:
    li=[]
    ans=1
    a+=[a[-1]+1]
    check=0
    for i in range(1,n):
      if abs(a[i]-a[i+1])>=2:print(0);exit()
      if a[i]!=a[i+1]:
        if li==[]:
          li.append(i)
          check=i
        else:
          li.append(i-check)
          check=i
    for i in range(len(li)-1):
      ans=ans*(li[i]**li[i+1])
      ans%=mod
    print(ans%mod)

Solution (Python):
from collections import Counter

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

mod = 998244353
c = Counter(d)

dp = [0]*n
if d[0] == 0 and c[0] == 1:
    dp[0] = 1
else:
    dp[0] = 0

for i in range(n):
    if i == 0:
        continue
    tmp = pow(c[i-1], c[i], mod)
    dp[i] = dp[i-1]*tmp % mod

ans = dp[-1]
print(ans)

Solution (Python):

import sys
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 998244353

n=int(input())
D=list(map(int,input().split()))
ans=1
data=[0]*(10**5)
M=0
for i in range(n):
    data[D[i]]+=1
    M=max(M,D[i])

for i in range(1,n-1):
    ans*=data[i-1]**data[i]
    ans=ans%mod
    

if D[0]!=0:
    ans=0
if data[0]>=2:
    ans=0
for i in range(M):
    if data[i] ==0:
        ans=0

print(ans%mod)

Solution (Python):
import sys
input = sys.stdin.readline
MOD = 998244353

n = int(input())
d = [int(item) for item in input().split()]
if d[0] != 0:
    print(0)
    exit()
max_val = max(d)
cnt = [0] * (max_val + 1)
for item in d:
    cnt[item] += 1
if 0 in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()

ans = 1
for a, b in zip(cnt, cnt[1:]):
    ans *= pow(a, b, MOD)
    ans %= MOD
print(ans)

Solution (Python):
import sys
import collections as co
n = int(input())
d = list(map(int,input().split()))
mod = 998244353
ans = 1
if d[0] != 0:
    print(0)
    sys.exit()

else:

    tmp = co.Counter(d)
    
    
    if tmp[0] != 1:
        print(0)
        sys.exit()
    for i in range(1,len(tmp)):
        ans *= (tmp[i-1] ** tmp[i]) % mod

print(ans%mod)

Solution (Python):
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res



def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = list(set(a))
    d = Counter(a)
    if a[0] != 0:
        print(0)
    elif a[0] == 0 and d[0] > 1:
        print(0)
    else:
        ans = 1
        for i in range(1, len(s)):
            if d[s[i] - 1] == 0 and s[i] > 0:
                print(0)
                exit()
            ans = (ans * modpow(d[s[i - 1]], d[s[i]], 998244353)) % 998244353
        print(ans)
            

    
    

        
        
        
            

    
   


if __name__ == '__main__':
    main()

Solution (Python):
import collections

def main():
    N=int(input())
    if N==0:
        return 0
    DL=[int(x) for x in input().split()]
    if DL[0]!=0:
        return 0
    
    
    dic=collections.Counter(DL)
    if dic[0]!=1:
        return 0
    keys=dic.keys()
    result=1
    for i in range(1,max(keys)+1):
        if dic[i]==0 and dic[i-1]==0:
            return 0
        result*=dic[i-1]**dic[i]

    return result%998244353


print(main())

Solution (Python):
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
flag = True
if d[0] != 0:
    flag = False
count = {}
for i in range(len(d) - 1):
    count.setdefault(d[i + 1], 0)
    count[d[i + 1]] += 1
count2 = []
for i, j in count.items():
    count2.append([i, j])
count2.sort()

ans = 1
if count2[0][0] == 1:
    for i in range(len(count2) - 1):
        if count2[i + 1][0] - count2[i][0] == 1:
            temp = count2[i][1] ** count2[i + 1][1]
            ans *= temp
            ans %= mod
        else:
            flag = False
            break
else:
    flag = False
if flag == True:
    print(ans)
else:
    print(0)

Solution (Python):
import sys
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    sys.exit()
d.sort()
d.append(-1)
if d[1] == 0:
    print(0)
    sys.exit()
i = 1
distance = 1
count = 0
while d[i] == distance:
    count += 1
    i += 1
branch = count
ans = 1
while True:
    count = 0
    distance += 1
    while d[i] == distance:
        count += 1
        i += 1
    ans *= (branch**count)%998244353
    branch = count
    if i >= n:
        break
print(ans%998244353)

Solution (Python):
from collections import Counter

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

counts = Counter(D)
Dmax = max(D)

flg = True
if D[0] != 0:
    flg = False
if counts[0] != 1:
    flg = False

if flg:
    ans = 1
    for i in range(1,Dmax+1):
        ans *= counts[i-1]**counts[i]
        ans %= 998244353
else:
    ans = 0

print(ans)

Solution (Python):
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

def main():
    d1 = D.pop(0)
    if d1 != 0:
        print(0)
        exit()

    c = Counter(D)
    item_list = list(c.items())
    item_list.sort()
    if item_list[0][0] != 1:
        print(0)
        exit()
    count = 1
    ans = 1
    item_list[0]
    for i in range(1, len(item_list)):
        if item_list[i][0] != count + 1:
            print(0)
            exit()
        count += 1
        ans *= (item_list[i-1][1]**item_list[i][1]) % MOD
        ans %= MOD
    
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353

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

cnt = collections.Counter(d)
total = 1
p = 1
if cnt[0] > 1:
    print(0)
    exit()
for i in range(1, n):
    if p == 0 and cnt[i] > 0:
        print(0)
        exit()
    total *= p**cnt[i]
    total %= mod
    p = cnt[i]
print(total % mod)

Solution (Python):
n = int(input())
d = list(map(int, input().split()))

ans = 1
cnt = [0] * (n)

for i in d:
  cnt[i] += 1

if d[0] != 0 or cnt[0] > 1:
  ans = 0
else:
  for i in range(2,n):
    ans *= cnt[i-1] ** cnt[i]
    ans %= 998244353

print(ans)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

a = [0 for _ in range(N)]
for d in D:
    a[d] += 1

if D[0] != 0 or a[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, N):
        ans = (ans * pow(a[i - 1], a[i], MOD)) % MOD
        
        
print(ans)

Solution (Python):
import sys
import collections
n = int(input())
d = list(map(int, input().split()))

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


d.sort()
c = collections.Counter(d)

if c[0] != 1:
    print("0")
    sys.exit()
    
ans = 1
for i in range(len(c)-1):
    x = c[i] ** c[i+1]
    ans *= x
    ans = ans % 998244353


print(ans)

Solution (Python):
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

mv = max(a)

xs = [0] * (mv+1)
for y in a:
    xs[y] += 1



if xs[0] > 1:
    print(0)
elif a[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(len(xs)-1):
        ans *= xs[i] ** xs[i+1]
        ans %= 998244353

    print(ans)

Solution (Python):
import sys
import itertools
input = sys.stdin.readline

N = int(input())
D = list(map(int, input().split()))
mod = 998244353

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

D.sort()
if D[1] == 0:
    print(0)
    exit()

gr = itertools.groupby(D[1:])
rank = 1
pre = 1
ans = 1
for key, group in gr:
    if rank != key:
        print(0)
        exit()
    cand = len(list(group))
    ans *= pre ** cand
    ans %= mod
    pre = cand
    rank += 1

print(ans)