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):
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
lis = [0] * (max(D)+1)
if D[0] != 0:
    print(0)
    exit()
for i in D:
    lis[i] += 1
if lis[0] == 0 or lis[0] > 1:
    print(0)
    exit()


ans = 1
for i in range(1,len(lis)):
    ans *= pow(lis[i-1],lis[i], MOD)
    ans %= MOD
print(ans)

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

def power(x,n,MOD):
    res=1
    if n>0:
        res=power(x,n//2,MOD)
        if (n%2==0):
            res=(res*res)%MOD
        else:
            res=(((res*res)%MOD)*x)%MOD
    
    return res

def main(n,d):
    MOD=998244353
    hist=[0]*(n+1)
    maxd=0
    for i in range(n):
        hist[d[i]]+=1
        maxd=max(maxd,d[i])
    

    ans=1
    if hist[0]>1:
        return 0
    if d[0]!=0:
        return 0
    for i in range(1,maxd+1):
        
        ans=(ans*power(hist[i-1], hist[i], MOD))%MOD
        

    return ans

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)

Solution (Python):
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
"""
def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)
"""

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

Solution (Python):
from collections import Counter


N = int(input())
D = list(map(int, input().split()))
p = 998244353
count = Counter(D)

if D[0] != 0 or len(set(D)) != max(D) + 1 or count[0] > 1:
    ans = 0
else:
    count = sorted(count.items(), key=lambda x: x[0])
    ans = 1
    for i in range(len(count) - 1):
        x = count[i][1]
        y = count[i + 1][1]
        ans *= x ** y
        ans %= p

print(ans)

Solution (Python):
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    D = [int(item) for item in input().split()]
    d_dict = collections.Counter(D)

    cnt = 0
    if D[0] != 0:
        pass
    else:
        cnt = 1
        for i in D[1:]:
            cnt *= d_dict[i-1]
            cnt %= 998244353


    print(cnt % 998244353)

if __name__ == "__main__":
    resolve()

Solution (Python):
N=int(input())
D=list(map(int, input().split()))
if D[0]!=0:
    print(0)
    exit()
if 0 in D[1:]:
    print(0)
    exit()
D=sorted(D)
p=998244353
edge=[0]*(N)

ans=1
for i in range(N):
    d=D[i]
    if i==0:
        if d==0:
            edge[0]+=1
            continue
        else:
            print(0)
            exit()
    if d==0:
        print(0)
        exit()
    if edge[d-1]==0:
        print(0)
        exit()
    else:
        edge[d]+=1
        ans*=edge[d-1]
        ans%=p

print(ans%p)

Solution (Python):
from collections import Counter
n = int(input())
l = list(map(int,input().split()))
c = Counter(l)
mod = 998244353
if l.count(0) != 1 or l[0] != 0:
    print(0)
    exit()
ans = 1
for i in l[1:]:
    ans *= c[i-1]
    ans %= mod
print(ans%mod)

Solution (Python):
n = int(input())
d = list(map(int,input().split()))
m = 998244353
import collections
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
else:
    ans = 0
d = sorted(d)
for i in range(1,n):
    ans *= c[d[i]-1]
    ans %= m
print(ans)

Solution (Python):
n = int(input())
d = list(map(int,input().split()))
m = 998244353
import collections
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
else:
    ans = 0
d = sorted(d)
for i in range(1,n):
    ans *= c[d[i]-1]
    ans %= m
print(ans)

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

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


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

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

for i in range(1,len(c)):
    if c[i][0]!=c[i-1][0]+1:
        print(0)
        exit(0)

ans=1
for i in range(1,len(c)):
    ans*=c[i-1][1]**(c[i][1])

print(ans%mod)

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



from collections import Counter
import sys

C = Counter(D)

if C[0] != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    CL = sorted(C.items())
    num_prev = -1
    val_prev = 1
    ans = 1
    for item in CL:
        num = item[0]
        val = item[1]
        if num != num_prev + 1:
            print(0)
            sys.exit()
        else:
            ans *= val_prev**val
            num_prev = num
            val_prev = val
    print(ans%998244353)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)



class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


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

if d[0] != 0:
    print(0)
    sys.exit()
d.sort()
cnt = [0 for i in range(n)]
for i in d:
    if i >= n:
        print(0)
        sys.exit()
    cnt[i] += 1


ans = 1
flag = True
for i in range(n):
    if i == 0:
        if cnt[i] != 1:
            ans = 0
            break
    elif cnt[i] == 0:
        flag = False
    elif not flag:
        ans = 0
        break
    else:
        ans *= cnt[i - 1] ** cnt[i]

print(ans % 998244353)

Solution (Python):
mod = 998244353

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

if D[0] != 0:
    res = 0
else:
    dict_D = {}
    for d in D:
        if d not in dict_D:
            dict_D[d] = 0
        dict_D[d] += 1

    max_D = sorted(D)[-1]

    res = 1
    parent = 1
    for i in range(max_D+1):
        if i == 0:
            if dict_D[0] != 1:
                res = 0
                break
        else:
            if i not in dict_D:
                res = 0
                break
            else:
                if i != 1:
                    res *= (parent**dict_D[i])
                    res %= mod
                parent = dict_D[i]

print(res)

Solution (Python):


import math



from collections import deque
from collections import Counter





Mod=998244353

n=int(input())
d=list(map(int,input().split()))
c=Counter(d)
ans=1
if d[0]!=0:
  print(0)
  exit()
for i in c:
  if i==0:
    if c[i]!=1:
      print(0)
      exit()
  else:
    if i-1 not in c:
      print(0)
      exit()
    else:
      ans*=pow(c[i-1],c[i],Mod)
      ans%=Mod
print(ans)

Solution (Python):
from collections import Counter

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

max_D = max(D_list)
cnt_dic = dict(Counter(D_list))

if (D_list[0] == 0) & (cnt_dic.get(0) == 1):
    ans = 1
    for n in range(1, max_D + 1):
        ans *= cnt_dic.get(n - 1, 0)  ** cnt_dic.get(n, 1)
    print(ans % 998244353)
else: 
    print(0)

Solution (Python):
def print0():
    print(0)
    exit()

n = int(input())
d = list(map(int, input().split()))
mod = 998244353
ans = 1
maxd = max(d)
numcnt = [0] * (maxd + 1)
for i in d:
    numcnt[i] += 1
if not d[0] == 0 or not numcnt[0] == 1:
    print0()
for i in range(1, maxd + 1):
    if numcnt[i] == 0:
        print0()
    ans *= pow(numcnt[i - 1], numcnt[i], mod)
    ans %= mod
print(ans)

Solution (Python):

"""
Created on Sat Jun 20 09:37:56 2020

@author: NEC-PCuser
"""

N = int(input())

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


if D[0] != 0:
    print(0)
else:
    n_count = [0] * 100000
    for i in range(N):
        n_count[D[i]] += 1
        
    count = 1
    ans = 1
    for j in range(1, len(n_count)):
        count += n_count[j]
        if n_count[j] == 0:
            break
        else:
            ans = (ans * (n_count[j - 1] ** n_count[j])) % 998244353
    if (count != N):
        print(0)
    else:
        print(ans)

Solution (Python):
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=998244353
 



def main():
	n = int(input())
	
	
	al = lin()
	if al[0] != 0:
		return 0
	if al.count(0) != 1:
		return 0
	
	alc = collections.Counter(al)
	mm = max(alc.keys())
	
	b = alc.keys()
	b=list(b)
	b.sort()
	if list(range(mm+1)) != b:
		
		return 0
		
	v = 1
	p=1
	for k in range(1, mm+1):
		num = alc[k]
		add = pow(p, num, mod)
		v *= add
		v %= mod
		p = num
	return v
		
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
N=int(input())
D=list(map(int,input().split()))
MOD=998244353
goal=-1
tree=[0]*(N)
ans=1
for i in range(N):
    a=D[i]
    goal=max(a,goal)
    tree[a]+=1
if tree[0]==1 and D[0]==0:
    for i in range(1,goal+1):
        ans*=pow(tree[i-1],tree[i],MOD)
        ans%=MOD
    print(ans)
else:
    print(0)

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline

N = int(input())
ans = 1
mod = 998244353
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = sorted(Counter(D).items())
tmp = D[0][1]
stream = 0
for n, i in D:
    if stream != n:
        print(0)
        exit()
    if n == 0 and i == 1:
        stream += 1
        continue
    elif n==0:
        print(0)
        exit()
    ans *= pow(tmp, i)
    ans %= mod
    tmp = i
    stream += 1
print(ans)

Solution (Python):
from collections import Counter
MOD = 998244353
n = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
else:
    cnt = Counter(D[1:])
    if 0 < cnt[0]:
        print(0)
    else:
        U = 10**5
        ans = 1
        prev_v = 1
        for i in range(1, U):
            ans *= pow(prev_v, cnt[i], MOD)
            ans %= MOD
            prev_v = cnt[i]
        print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


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


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
A = IL()
M = max(A)
dic = DD(int)
for a in A:
  dic[a] += 1
if dic[0] != 1 or A[0] != 0:
  print(0)
  exit()
else:
  ans = 1
  for i in range(M):
    ans *= pow(dic[i],dic[i+1])
    ans %= 998244353

print(ans)

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

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

max_d = max(d)
cnt = [0] * (max_d + 1)

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

if cnt[0] > 1:
    print(0)
    exit(0)

ans = 1

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

print(ans)

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

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

max_d = max(d)
cnt = [0] * (max_d + 1)

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

if cnt[0] > 1:
    print(0)
    exit(0)

ans = 1

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

print(ans)

Solution (Python):
from collections import Counter

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

dcnt = Counter(d)
if d[0] > 0 or dcnt[0] > 1:
    print(0)
else:
    ans = 1
    for i in dcnt:
        if i > 0:
            ans = ans * dcnt[i - 1]**dcnt[i] % mod
    print(ans)

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

a = [0] * n
for d_ in d:
    a[d_] += 1

res = d[0] == 0 and a[0] == 1
for i, j in zip(a, a[1:]):
    res = res * i ** j % mod

print(res)

Solution (Python):



from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    Dc = Counter(D)

    if D[0]!=0 or Dc[0]!=1:
        print(0)
    else:
        mx = max(D)
        mod = 998244353
        ret = 1
        for i in range(1, mx+1):
            ret *= pow(Dc.get(i-1,0), Dc.get(i,0), mod)
            ret %= mod
        print(ret)

if __name__ == '__main__':
    main()

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

a = [0] * n
for d_ in d:
    a[d_] += 1

res = d[0] == 0 and a[0] == 1
pre = 1
for a_ in a:
    res = res * pre ** a_ % mod
    pre = a_

print(res)

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

a = [0] * n
for d_ in d:
    a[d_] += 1

res = d[0] == 0 and a[0] == 1
pre = 1
for a_ in a:
    res *= pre ** a_
    res %= mod
    pre = a_

print(res)

Solution (Python):
from collections import Counter

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

a = sorted(list(set(d)))

if d[0] != 0:
    ans = 0
elif a[-1] != len(a)-1:
    ans = 0
else:
    c = sorted(Counter(d).items())
    if c[0] != (0, 1):
        ans = 0
    else:
        ans = 1
        pre = 1
        for k, v in c:
            ans *= pre ** v
            ans %= mod
            pre = v

print(ans)

Solution (Python):
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if D[0] != 0 or cnt_D.get(0, 0) != 1:
    print(0)
else:
    prev = 1
    ans = 1
    for i in range(1, max(D) + 1):
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

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

c = Counter(d)
max_d = max(d)
ans = 1
previous_leaf = 1


if d[0] != 0:
    ans = 0

elif c[0] != 1:
    ans = 0

else:
    for i in range(1,max_d+1):
        ans *= (previous_leaf**c[i])
        ans %= 998244353

        
        previous_leaf = c[i]
print(ans)

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    D = list(map(int, input().split()))
    p = 998244353
    if D[0] > 0:
        exit(print(0))
    l = Counter(D)
    if l[0] > 1:
        exit(print(0))
    ans = 1
    for i in range(1,max(l)+1):
        if l[i] == 0:
            exit(print(0))
        ans *= pow(l[i-1],l[i],p)
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    import sys
    n,*d=map(int,sys.stdin.buffer.read().split())
    e=[0]*n
    for i in d:
        e[i]+=1
    a=1 if d[0]<1 else 0
    for i in d[1:]:a=a*e[i-1]%998244353
    print(a)
main()

Solution (Python):
from collections import Counter
MOD = 998244353

N = int(input())

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

if D[0] > 0:
    print(0)
    exit()

c = Counter(D)
if c[0] > 1:
    print(0)
    exit()

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

print(ans%MOD)

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

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

counts = [0] * (max(D) + 1)

from collections import Counter
counter = Counter(D)

for k,v in counter.items():
  counts[k] = v

if D[0] != 0 or counts[0] != 1:
  print(0)
  exit(0)
  
ans = 1
DIV = 998244353
for i in range(1, len(counts)):
  ans *= pow(counts[i - 1],counts[i],DIV)
  ans %= DIV

print(ans)

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

if d[0]!=0:
  print(0)
  exit(0)
  
m=max(d)
counts=[0]*(m+1)

import collections
counter=collections.Counter(d)

for key,val in counter.items():
  counts[key]=val
if counts[0]!=1:
  print(0)
  exit(0)
ans=1
div=998244353
for i in range(1,len(counts)):
  ans*=pow(counts[i-1],counts[i],div)
  ans%=div
  
print(ans)

Solution (Python):
n = int(input())
dl = list(map(int,input().split()))
if dl[0] != 0:
  print(0)
  exit()
d_dic = dict()
for d in dl:
  if d in d_dic:
    d_dic[d] += 1
  else:
    d_dic[d] = 1
l = max(d_dic.keys())
for i in range(l):
  if not i in d_dic:
    print(0)
    exit()
if d_dic[0] != 1:
  print(0)
  exit()
ans = 1
for i in range(l):
  ans *= d_dic[i]**d_dic[i+1]
  ans = ans%998244353
print(ans)

Solution (Python):
import sys
from collections import Counter
N = int(sys.stdin.readline().rstrip())
D = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 998244353

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

d_cnt = sorted(Counter(D).items())

ans = 1
par = 1
prev = 0
for k, v in d_cnt:
    if k > 0:
        if prev + 1 == k:
            ans *= pow(par, v, mod)
            ans %= mod
            par = v
            prev = k
        else:
            print(0)
            exit()
print(ans)

Solution (Python):
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353

maxi=max(d)

ans=1
if D[0]!=0:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for i in range(1,maxi+1):
      if i not in d:
        print(0)
        exit()
      else:
        s =  (d[i-1]**d[i])%p
        ans = (ans * s)%p
    print(ans)

Solution (Python):
mod = 998244353


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

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

CNT = [0] * n
for d in D:
    CNT[d] += 1

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

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

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]




mod=998244353
n=ii()
arr=limii()

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

if n==1 and arr[0]==0:
    print(1)
    exit()


chk=True

p=Counter(arr)

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

tmp=0
for i in range(1,max(list(p))+1):
    if p[i]>0:
        pass
    else:
        print(0)
        exit()

ans=1



def mul(a, b):
    return ((a % mod) * (b % mod)) % mod



def div(a,b):
    return a*pow(b, mod-2, mod)



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

for i in range(max(p.keys())):
    
    ans=(ans*pow(p[i], p[i+1], mod)) %mod
    
print(ans%mod)

Solution (Python):
N=int(input())
import collections
l=list(map(int,input().split()))
cnt=collections.Counter(l)
if cnt[0] > 1 or l[0] != 0:
   print(0)
   exit()
ans=1
mod=998244353
for i in range(1,max(cnt)):
   ans*=pow(cnt[i],cnt[i+1],mod)
   ans%=mod
print(ans)

Solution (Python):
from statistics import median


from fractions import gcd
from itertools import combinations 
from collections import deque
from collections import defaultdict
import bisect










import sys
sys.setrecursionlimit(10000000)

mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
flag = False
n = I()
D = readInts()
dic = defaultdict(int)
for i in range(n):
    dic[D[i]] += 1

for i in range(n-1,0,-1):
    if dic[i] != 0:
        flag = True
    if flag and dic[i] == 0:
        print(0)
        exit()
if dic[0] != 1: 
    print(0)
    exit()
if D[0] != 0: 
    print(0)
    exit()
ans = 1

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

Solution (Python):
n,*a=map(int,open(0).read().split())
mod=998244353
b=[0]*n
for i in a:
    b[i]+=1
ans=0
if a[0]==0 and 1==b[0]:
    ans=1
for i,j in zip(b,b[1:]):
    ans=ans*i**j%mod
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
mod=998244353
d={}
for i in a:
  d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]+1 or b[0][1]!=1:
    ans=0
for i in range(1,len(b)):
    ans*=b[i-1][1]**b[i][1]
    ans%=mod
print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
if a[0]:
    print(0)
    exit()
a.sort()
j=0
l=list()

for i in range(max(a)+1):
    k=0
    while j<n and a[j]==i:
        j+=1
        k+=1
        
    l.append(k)

p=l[0]==1
mod=998244353
for i in range(len(l)-1):
    
    p=(p*pow(l[i],l[i+1],mod))%mod
print(p%mod)

Solution (Python):
from collections import Counter

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

Solution (Python):

from collections import*
n, *d= map(int, open(0).read().split())
c = Counter(d)
if d[0] or c[0] > 1:
    exit(print(0))
MOD = 998244353
m = 1
for i in range(1, max(d)):
    m *= pow(c[i], c[i + 1], MOD)
    m %= MOD
print(m)

Solution (Python):
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = int(input())
data = list(map(int, input().split()))
if data[0] != 0:
    print(0)
    exit()
data = count(data)
mod = 998244353
if data[0] != 1:
    print(0)
    exit()
ans = 1
for depth, edges in data.items():
    if depth == 0:
        continue
    if depth - 1 not in data:
        print(0)
        exit()
    ans *= data[depth-1]**edges
    ans %= mod
print(ans%mod)

Solution (Python):
from collections import Counter
mod = 998244353
num_nodes = int(input())
d_ls = list(map(int, input().split()))
d_max = max(d_ls)
c = Counter(d_ls)

if c[0] == 1 and d_ls[0] == 0 and c[1] > 0:
    ans = 1
else:
    ans = 0

for i in range(1,d_max):
    ans *= c[i] ** c[i+1]
    ans %= mod
print(ans)

Solution (Python):
import collections
mod = 998244353

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

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

Dep = collections.Counter(D)
values, counts = zip(*Dep.most_common())



ans = 1
for i in range(1,len(values)):
    if Dep[i-1] == 0:
        ans = 0
    ans *= pow(Dep[i-1],Dep[i], mod)
    
    ans %= mod
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]





N = ii()
A = li()
max_num = 10**5+1
num_list = [0] * (max_num)

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

for num in A:
    num_list[num] += 1

if num_list[0] > 1:
    print(0)
    exit()

ans = 1
for i in range(2, max_num):
    if num_list[i] != 0:
        ans *= pow(num_list[i-1], num_list[i], 998244353)

else:
    print(ans%998244353)

Solution (Python):
N = int(input())
D = list(map(int, input().split()))
DL = [0] * N
mod = 998244353
if D[0] != 0:
    print(0)
    exit()

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

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

ans = 1
for i in range(1, N):
    if DL[i] == 0:
        if sum(DL[i:]) != 0:
            print(0)
            exit()
        else:
            print(ans%mod)
            exit()

    ans *= pow(DL[i-1], DL[i], mod)
    ans %= mod
print(ans % mod)