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())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
else:
    D.sort()

    if D[1] == 0:
        print(0)
    else:
        mod = 998244353
        ans = 1
        distance = 0
        prev = 1
        now = 0

        for i in range(N):
            if D[i] == distance:
                now += 1
            elif D[i] == distance + 1:
                ans = (ans % mod) * (prev ** now % mod) % mod
                prev = now+0
                now = 1
                distance += 1
            else:
                ans = 0
                break
        else:
            ans = (ans % mod) * (prev ** now % mod) % mod
        
        print(ans)

Solution (Python):
import sys
n = int(input())
d = list(map(int, input().split()))
m = {}
ans = 1

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

if d.count(0) > 1:
    print(0)
    sys.exit()

for i in range(n):
    num = d[i]
    if num in m:
        m[num] += 1
    else:
        m[num] = 1







maxV = max(m.keys())



for i in range(0, maxV):
    if i not in m or i + 1 not in m:
        print(0)
        sys.exit()
    prevCnt = m[i]
    curCnt = m[i+1]
    
    
    ans *= prevCnt ** curCnt
    

print(ans % 998244353)

Solution (Python):
from collections import Counter

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

Solution (Python):
import sys

def main():
    N = int(input())
    D = list(map(lambda i: int(i), input().split(' ')))
    
    
    
    

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

    ary = [0] * N
    for d in D:
        ary[d] = ary[d] + 1

    
    zero = False
    for i in range(len(ary)):
        if ary[i] != 0 and zero is True:
            print(0)
            sys.exit()
        if ary[i] == 0 and zero is False:
            zero = True

    
    if ary[0] != 1:
        print(0)
        sys.exit()

    answer = 1
    for i in range(1, len(ary)):
        for j in range(ary[i]):
            answer = (answer * ary[i - 1]) % 998244353
    print(answer)

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()
D=Counter(d)
l=len(D)

ans=1
for i in range(l):
  if i==0:
    if D[i]!=1:
      print(0)
      exit()
  else:
    if D[i]==0:
      print(0)
      exit()
    else:
      ans=(ans*((D[i-1]**D[i])%mod))%mod
print(ans)

Solution (Python):
from collections import Counter
from itertools import tee

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


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def is_leap(distance):
    cc = Counter(distance)
    for x, y in pairwise(sorted(cc.keys())):
        if y - x > 1:
            return True
    else:
        return False


if D[0] > 0:
    """頂点1が根ではない"""
    print(0)
elif not all(D[1:]):
    """連結グラフではない"""
    print(0)
elif is_leap(D):
    print(0)
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e)
    print(ans % R)

Solution (Python):
from collections import Counter
n = int(input())
d = [int(_) for _ in input().split()]
c = Counter(d)
ans = 0
dmax = max(d)

f = 1
for i in range(dmax+1):
    f *= c[i]

if d[0] == 0 and c[0] == 1 and f:
    ans = 1
    if dmax > 1:
        for i in range(2, dmax+1):
            ans *= c[i-1]**c[i]
print(ans%998244353)

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

N = int(input())
D = list(map(int, input().split()))
C = Counter(D)
if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, max(D)+1):
    if C[i] == 0:
        ans = 0
        break
    else:
        ans *= pow(C[i-1], C[i], MOD)
        ans %= MOD
print(ans)

Solution (Python):
import collections
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
c = collections.Counter(D)
if c[0] != 1:
    print(0)
    exit()

ans = 1

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

Solution (Python):
import collections


N=int(input())
D=list(map(int,input().split()))
A=collections.Counter(D)
if D[0]==0 and len(set(D))==max(D)+1 and A[0]==1:
  c=1
  for i in range(max(D)):
    c*=A[i]**A[i+1]
  ans=c%998244353  
  print(ans)
else:
  print(0)

Solution (Python):
import sys
from collections import Counter, deque, defaultdict, OrderedDict
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))


MOD = 998244353
n = INT()
d = LIST()
if d[0] != 0:
    print(0)
    sys.exit()
d = d[1:]
c = dict(Counter(d))
c =  OrderedDict(sorted(c.items()))
c = list(c.values())
if len(c) != max(d):
    print(0)
    sys.exit()
res = 1
for i in range(1, len(c)):
    res *= c[i-1]**c[i]

print(res%MOD)

Solution (Python):
import sys
import collections
def solve():
    sys.setrecursionlimit(100000)
    mod = 998244353

    N = int(input())
    D = list(map(int, input().split()))
    ans = 1
    if D[0] != 0:
        ans = 0
        print(ans)
        exit(0)
    
    cnter = collections.Counter(D)
    cnter = sorted(cnter.items())

    if cnter[0][0] != 0 or cnter[0][1] != 1 : 
        ans = 0
    elif len(cnter) == 1:
        ans = 1
    elif cnter[1][0] != 1:
        ans = 0
    else:
        for i in range(2, len(cnter)):
            if cnter[i][0] != i:
                ans = 0
                break

            else:
                ans = ans * modpow(cnter[i-1][1], cnter[i][1], mod) % mod
    
    print(ans)


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

if __name__ == '__main__':
    solve()

Solution (Python):
import numpy as np

N = int(input())
D = np.array([int(a) for a in input().split()])

num_at_dist = np.array([1] + [0] * (N-1) + [0]) 

if D[0] != 0:
    ans = 0
else:
    ans = 1
    D = np.sort(D)
    for i in range(1, N):
        dist = D[i]
        num_at_dist[dist] += 1
        ans = ( ans * num_at_dist[dist - 1] ) % 998244353

print(ans % 998244353)

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

for i in range(1, n):
    if l[i] == 0:
        print(0)
        exit()

max_vertex = max(l)
ll = []
l=sorted(l)
l.append(-4)
c=1
for i in range(1, n):
    if l[i] != l[i+1]:
        if l[i] != l[i+1]-1 and l[i+1] > 0:
            print(0)
            exit()
        ll.append(c)
        c = 0
    c+=1

count = 1
for i in range(1, max_vertex):
    tmp = ll[i-1]
    count *= pow(tmp, ll[i])
print(count%998244353)

Solution (Python):
from collections import Counter

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

Solution (Python):
from collections import Counter

n = int(input())
s = input()
if s[0] != '0':
    print(0)
    exit()

d = Counter(map(int, s.split()))
mod = 998244353

if 0 not in d or d[0] > 1:
    print(0)
    exit()
if n == 1:
    print(1)
    exit()

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

print(ans % mod)

Solution (Python):
import collections
 
n = int(input())
d = list(map(int, input().split()))
for i in range(len(d)):
    if i == 0 and d[i] != 0:
        print(0)
        exit()
    if i != 0 and d[i] == 0:
        print(0)
        exit()
 
e = collections.Counter(d)
 
e2 = dict(sorted(e.items()))
e3 = list(e2.values())
e4 = list(e2.keys())



 
tmp = 0
for i in e4:
    if i - tmp >= 2:
        print(0)
        exit()
    tmp = i
cntsum = 1
for i in range(1, len(e3)):
    cntsum *= e3[i - 1] ** e3[i]
print(cntsum%998244353)

Solution (Python):
import bisect
N=int(input())
D=list(map(int,input().split()))
if D[0]==0 and D.count(0)==1:
    D.sort()
    m=max(D)
    counter=[]
    for i in range(m+1):
        counter.append(bisect.bisect_right(D,i)-bisect.bisect_left(D,i))
    ans=1
    for i in range(1,m+1):
        ans*=counter[i-1]**counter[i]
    print(ans%998244353)
else:
    print(0)

Solution (Python):
mod = 998244353
n=int(input())
d=[int(i) for i in input().split()]
ans=[0]*n
for i in d:
    ans[i]+=1
f=mod
for i in ans:
    if f==0 and i>0:
        print(0)
        exit()
    f=min(f,i)
if d.count(0)!=1 or d[0]!=0:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    if ans[i-1]==0:
        break
    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod

print(cnt%mod)

Solution (Python):
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    sys.exit()
E = D[1:]
d = dict(Counter(E))
sum_=1
temp=1
max_n=max(d.keys())
if len(d) ==1:
    if list(d.keys()) == [0]:
        print(0)
        sys.exit()
if 0 in d.keys():
    print(0)
    sys.exit()
for i in range(1,max_n+1):
    try:
        add = (temp ** d[i]) % lim
        sum_ = (sum_ * add) % lim
        temp = d[i]
    except:
        print(0)
        sys.exit()
print(sum_)

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

if d[0] != 0 or d.count(0) != 1:
    print(0)
else:
    d.sort()
    ans = 1
    nx = 0
    pre = 1
    cnt = 0
    for i in range(n):
        if d[i] == nx:
            cnt += 1
        else:
            if d[i] == nx + 1:
                ans = ans * pre ** cnt
                pre = cnt
                cnt = 1
                nx += 1
            else:
                ans = 0
                break
    ans = ans * pre ** cnt
    print(ans%wari)

Solution (Python):
from collections import Counter

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

if L[0] != 0 or any(l == 0 for l in L[1:]):
    print(0)
    exit()

C = Counter(L)
MOD = 998244353
ans = 1
for i, j in enumerate(range(1, max(L)+1)):
    prev = C[i]
    cur = C[j]
    ans *= prev**cur
    ans %= MOD
print(ans)

Solution (Python):
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    exit()
c=Counter(d)
c=sorted(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)

Solution (Python):
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
if D[0] != 0: print(0)
else:
    D = sorted(D)
    levels = [0 for _ in range(D[-1]+1)]
    for d in D:
        levels[d] += 1
    if 0 in levels or levels[0] > 1: print(0)
    else:
        ans = 1
        for l1, l2 in zip(levels, levels[1:]):
            ans = (ans * pow(l1, l2, MOD)) % MOD
        print(ans)

Solution (Python):

divider = 998244353

num = int(input())
depths = [int(x) for x in input().split()]
max_depth = max(depths)

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

if max_depth == 0:
  print(0)
  exit(0)

nodes = [0] * (max_depth+1)

for depth in depths:
  nodes[depth] += 1

if nodes[0] != 1 or min(nodes) == 0:
  print(0)
  exit(0)

arr = [nodes[i] ** nodes[i+1] for i in range(max_depth)]

ans = 1
for a in arr:
  ans = (ans * a)  % divider

print(ans)
exit(0)

Solution (Python):
from collections import Counter

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

L = sorted(set(D))
d = Counter(D)
s = 0

if (D[0] == 0) and (list(range(max(D) + 1)) == L):
    if (d[0]==1) and (1 in d):
        s = 1
        for l in L[1:-1]:
            for i in range(d[l + 1]):
                s *= d[l]
                s %= 998244353
print(s)

Solution (Python):
import collections


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

c = collections.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])
        previous_leaf = c[i]

print(ans % 998244353)

Solution (Python):
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ans = 1
ans_ = 1
for i in range(len(D_)):
    temp = D_[i]
    if D[0] != 0:
        print(0)
        ans_ = 0
        break
    elif i == 0 and temp > 1:
        print(0)
        ans_ = 0
        break
    elif temp ==0:
        print(0)
        ans_ = 0
        break
    elif i > 0:
        ans *= D_[i-1] ** D_[i]
        ans %= 998244353
if ans_:
    print(ans)

Solution (Python):
import collections
N = int(input())
D = list(map(int,input().split()))
if D[0] == 0:
    if D.count(0) == 1:
        A = collections.Counter(D)
        result = 1
        for i in range(max(D)):
            result *= A[i] ** A[i + 1]
        print(result % 998244353)
    else:
        print(0)
else:
    print(0)

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

r = [None] * N
m = 0

for i, j in enumerate(D):
    if (i == 0 and j != 0) or (i != 0 and j == 0):
        print("0")
        exit()
    r[j] = 1 if r[j] is None else r[j] + 1
    if j > m:
        m = j

result = 1
pre = None

for i, x in enumerate(r):
    if x is None:
        if i != m + 1:
            print("0")
            exit()
        else:
            break
    if i < 2:
        pre = x
        continue
    result *= pre**x
    pre = x

print(result % 998244353)

Solution (Python):
import collections

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

cnt = collections.Counter(D)

if D[0] != 0:
    ans = 0
elif cnt[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, max(D)+1):
        if cnt[i] == 0:
            ans = 0
            break
        else:
            ans *= cnt[i-1] ** cnt[i]

print(ans%998244353)

Solution (Python):
import collections


def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    if counter[0] != 1 or d[0] != 0:
        return 0
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

Solution (Python):
mod=998244353
def modpow(a,r):
    ret=1
    while r>0:
        if r%2==1:
            ret*=a
            ret%=mod
        a*=a
        a%=mod
        r//=2
    return ret
n=int(input())
ds=[int(i) for i in input().split()]
if ds[0]!=0:
    print(0)
else:
    ma=max(ds)
    cnt=[0 for i in range(ma+1)]
    for i in ds:
        cnt[i]+=1
    if cnt[0]!=1 or min(cnt)==0:
        print(0)
    else:
        res=1
        for i in range(1,ma+1):
            res*=modpow(cnt[i-1],cnt[i])
            res%=mod
        print(res)

Solution (Python):
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
    print(0)
    exit()
for d in D[1:]:
    if d==0:
        print(0)
        exit()
C=Counter(D)
m=max(D)
ans=1
for i in range(2,m+1):
    ans*=pow(C[i-1],C[i],mod)
    ans%=mod
print(ans)

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

dict = {}
for i in range(N):
    if list[i] in dict.keys():
        dict[list[i]] += 1
    else:
        dict.setdefault(list[i], 1)

max = max(dict)

try:
    for i in range(1,max+1):
        ans = (ans * (dict[i-1] ** dict[i])) % 998244353
    if dict[0] != 1:
        ans = 0
    if list[0] != 0:
        ans = 0
except KeyError:
    ans = 0

print(ans)

Solution (Python):


def solve():
    N = int(input())
    D = [int(i) for i in input().split()]
    
    mD = max(D)
    nD = [0] * (mD + 1)
    for d in D:
        nD[d] += 1
    
    if D[0] != 0:
        print(0)
        return
    
    if nD[0] != 1:
        print(0)
        return
    count = nD[0]
    for i in range(2, len(nD)):
        count *= nD[i - 1] ** nD[i]
        count = count % 998244353
    print(count)


if __name__ == '__main__':
    solve()

Solution (Python):
import collections
N = int(input())

D = [int(a) for a in input().split() ]

counted = collections.Counter(D)

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


result = 1
x = counted[1]
for i in range(2,N+1):
    y = counted[i]
    result = result * pow(x,y) %998244353
    x = y
print(result)

Solution (Python):
import sys
import collections

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

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

if c==[(0,1)]:
	print(1)
	sys.exit()

if d[0]!=0 or c[0]!=(0,1):
	print(0)
	sys.exit()

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

print(ans%mod)

Solution (Python):
import sys
import collections

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

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

if c==[(0,1)]:
	print(1)
	sys.exit()

if d[0]!=0 or c[0]!=(0,1):
	print(0)
	sys.exit()

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

print(ans%mod)

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

L = [0] * N

for d in D:
    L[d] += 1
if D[0] != 0:
    print(0)
    sys.exit()
total = 1
prev_l = 1
for i, l in enumerate(L):
    if i == 0:
        prev_l = l
        if l != 1:
            total = 0
            break
        continue
    total *= (prev_l**l)
    total %= MOD
    prev_l = l

print(total%MOD)

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
if n==1 or d[0]!=0:
    ans=0
d=sorted(d)
for j in range(0,n-1):
        if d[j+1]-d[j]>1:
            ans=0
            break
        
if d[0]!=0 or d[1]==0:
    ans=0
else:
    for i in range(1,n-1):
        if d[i]==d[i+1]:
            a+=1
        else:
            ans=ans*(b**a)
            b=a
            a=1
ans=ans*(b**a)
ans=ans%998244353
print(ans)

Solution (Python):
from collections import Counter
import sys

N = int(input())
D_list = list(map(int, input().split()))
if D_list[0] != 0:
    print(0)
    sys.exit()
P = 998244353
n = 1
c = Counter(D_list)
if c[0] != 1:
    print(0)
else:
    pre = 1
    for i in range(1, max(D_list) + 1):
        if c[i] == 0:
            print(0)
            sys.exit()
        n = (n * ((pre ** c[i]) % P)) % P
        pre = c[i]
    print(n)

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

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

waru = 998244353

dic = {}
dic2 = {}

for i in range(1, N+1):
    dic[i] = D[i-1]

for number, distance in dic.items():
    if distance in dic2:
        dic2[distance] = dic2[distance] + 1
    else:
        dic2[distance] = 1

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

l = []

for i in range(1, len(dic2.items()) - 1):
    if i in dic2 and (i+1) in dic2:
        l.append(dic2[i] ** dic2[i+1])
    else:
        print(0)
        exit(0)

r = 1
for x in l:
    r *= x

d, m = divmod(r, waru)
print(m)

Solution (Python):
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
else:
  m=max(a)
  b=[0]*m
  flag=True
  for i in a[1:]:
    if i==0:
      print(0)
      flag=False
    b[i-1]+=1
  if flag:
    res=1
    
    for i in range(1,len(b)):
      res*=b[i-1]**b[i]

    print((res)%998244353)

Solution (Python):
n = int(raw_input())
a = map(int,raw_input().split())

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

a.sort()

if a[1] != 1:
  print 0
  exit(0)
  
ans = 1
old = 1
now = 1
c = 0

for q in range(1,len(a)):
  ans %= 998244353

  if now != a[q]:
    if now+1 != a[q]:
      print 0
      exit(0)
    else:
      ans = ans * pow(old,c,998244353)
      old = c
      c = 1
      now = a[q]
  else:
    c += 1
ans = ans * pow(old,c,998244353)

ans %= 998244353
print ans

Solution (Python):

n=int(input())
d=[int(i) for i in input().split()]

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or set(d)!=set(range(len(set(d)))) or 0 in d[1:]:
    print(0)
else:
    for i in range(1,len(c)):
        ans = (ans* c[i-1]**c[i]) %m
    print(ans)

Solution (Python):
import sys
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
if xs[0] != 0:
    print(0)
    sys.exit()
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
if cc[0] != 1:
    print(0)
    sys.exit()
r = 1
for i in range(mm):
    r = (r * pow(cc[i], cc[i+1])) % MM
print(r)

Solution (Python):
mod = 998244353
n = int(input())
import collections
dat = list(map(int, input().split()))
c = collections.Counter(dat)
ma = max(c)

res = 1

can = True

for i in range(1,ma ):
    
    
    
    if c[i] == 0:
        can = False
        break
    for ii in range(c[i+1]):
        res *= c[i]
        res %= mod
        


if dat[0] != 0:
    print(0)
elif c[0] != 1:
    print(0)
elif can is False:
    print(0)
else:
    print(res)

Solution (Python):

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
DD = inpl()
cnts = defaultdict(int)
for d in DD:
    cnts[d] += 1

m = max(DD)

if DD[0] != 0 or cnts[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1,m+1):
        if cnts[i] == 0:
            print(0)
            sys.exit()
        ans *= pow(cnts[i-1],cnts[i],mod)
        ans %= mod

    print(ans%mod)

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

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

count = 1
dmax = max(d)
num_array = [0] * (dmax+1)

for i in range(len(d)):
    num_array[d[i]] += 1

if num_array[0] != 1:
    print("0")
    exit()
for i in range(1, dmax+1):
    count *= num_array[i-1] ** num_array[i]
    count %= 998244353
print(count)

Solution (Python):
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    D = list(map(int, input().split()))
    count = Counter(D)
    result = 1
    if D[0] != 0 or count[0] != 1:
        print(0)
        return
    for i in range(max(D)):
        result *= count[i] ** count[i + 1]
    print(result % 998244353)


if __name__ == "__main__":
    main()

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

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

cnt = collections.Counter(D)
if cnt[0] != 1:
    print(0)
    exit()
    
ans = 1
limit = max(cnt.keys()) + 1
for i in range(0, limit):
    if i == limit - 1:
        break
    n = cnt[i]
    r = cnt[i + 1]
    if n == 0 or r == 0:
        ans = 0
        break
    ans *= n ** r

print(ans % 998244353)

Solution (Python):
import numpy as np
import collections

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

D_seq_max = max(D_seq)

judge_list = np.arange(D_seq_max+1)
judge_set = set(judge_list)
D_seq_set = set(D_seq)

c = collections.Counter(D_seq)

N_list = []
if((judge_set == D_seq_set)and(D_seq[0]==0)):
    if(c[0]>1):
        print(0)
    else:
        counts = 1
        for i in range(D_seq_max):
            counts *= pow(c[i], c[i+1])
        if(counts < 998244353):    
            print(counts)
        else:
            print(int(counts%998244353))
else:
    print(0)

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
k=max(ls)
ls2=[0 for i in range(k+1)]
for e in ls:
  ls2[e]+=1
if ls2[0]!=1 or ls[0]!=0:
  print(0)
else:
  ans=1
  for i in range(1,k):
    for j in range(ls2[i+1]):
      ans=(ans*ls2[i])%998244353
  print(ans)

Solution (Python):
mod = 998244353
 
N = int(input())
D = list(map(int,input().split()))
 
C = [0]*N
 
for i in range(N):
    C[D[i]]+=1
 
if D[0]!=0:
    print(0)  
elif C[0]==1:
    counter=1
    ans = 1
    for i in range(1,N):
        if C[i]==0 and counter<N:
            ans = 0
            break
        elif C[i]==0:
            break
        else:
            ans *= pow(C[i-1] ,C[i], mod)
            ans %= mod
            counter += C[i]
    print(ans)
else:
    print(0)

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

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

D.sort()
ans = 1
count = {}
for i in range(N):
  if i > 0:
    if D[i]-1 in count:
      ans *= count[D[i]-1]
      ans %= MOD
    else:
      print(0)
      exit()
  if D[i] in count:
    count[D[i]] += 1
  else:
    count[D[i]] = 1
print(ans)

Solution (Python):
mod = 998244353

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

p = [0]*(n)
for i in range(n):
    p[d[i]]+=1

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

if p[0]!=1:
    print(0)
    exit()
ans = 1
j = 1
for i in range(1,n):
    if p[i]==0:
        break

    ans = (ans*(p[i-1]**p[i]))%mod
    j +=p[i]
if j==n:
    print(ans)
else:
    print(0)

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 1 and D[0] == 0:
    for i in range(1,maxkey): 
        ans=ans*(dic[i]**dic[i+1])%MOD
    print(ans)
else:
    print(0)

Solution (Python):
mod = 998244353
kaizyo = [1, 1]
for i in range(2, 100005):
    kaizyo.append(kaizyo[-1]*i % mod)




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

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

prime_D = set(D)
prime_D = list(prime_D)
counter = {}

for i in range(len(prime_D)):
    counter[prime_D[i]] = 0

for i in range(len(D)):
    counter[D[i]] += 1  

counter = sorted(counter.items(), key=lambda x: x[0])

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


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


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


print(ans % mod)

Solution (Python):
N = int(input())
D = list(map(int,input().split()))
import collections as col
E = col.Counter(D)
def tree(L):
    t = 1
    if L[0] != 1:
        return 0
    else:
        for i in range(1,len(L)):
            t = t * (L[i-1]**L[i])
            t = t % 998244353
        return t
def number(D,E):
    if D[0] == 0:
        return tree(E)
    else:
        return 0
print(number(D,E))

Solution (Python):
LARGE = 998244353


def solve(n, d_list):
    cnt = [0] * (max(d_list) + 1)
    for i in range(n):
        cnt[d_list[i]] += 1
    if cnt[0] != 1 or d_list[0] != 0:
        return 0
    res = 1
    for i in range(max(d_list)):
        res *= pow(cnt[i], cnt[i + 1], LARGE)
        res %= LARGE
    return res


def main():
    n = int(input())
    d_list = list(map(int, input().split()))
    res = solve(n, d_list)
    print(res)


def test():
    assert solve(4, [0, 1, 1, 2]) == 2
    assert solve(4, [1, 1, 1, 1]) == 0
    assert solve(7, [0, 3, 2, 1, 2, 2, 1]) == 24


if __name__ == "__main__":
    test()
    main()

Solution (Python):
N=int(input())
ld=list(map(int,input().split()))
def modpow(a,n,p):
    res=1
    while n>0:
        if n&1:
            res=res*a%p
        a=a*a%p
        n>>=1
        
    return res
if ld[0]!=0:
    print(0)

else:
    dd={}
    for i in range(N):
        if ld[i] in dd:
            dd[ld[i]]+=1
        else:
            dd[ld[i]]=1

    if dd[0]!=1:
        print(0)
    else:
        DV=998244353
        ans=1
        for i in range(0,len(dd)-1):
            
            if i in dd and i+1 in dd:
                mul=modpow(dd[i],dd[i+1],DV)
                
                ans*=mul
                ans%=DV
            else:
                print(0)
                break
        else:
            print(ans)

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

import collections
c = collections.Counter(d)
if d[0] == 0:
    if c[0] != 1:
        print(0)
    else:
        result = 1
        for i in range(1, len(c)):
            result *= c[i-1]**c[i]
            result = result%998244353
        print(result)
else:
    print(0)

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

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

count = 1
dmax = max(d)
num_array = [0] * (dmax+1)

for i in range(len(d)):
    num_array[d[i]] += 1

if num_array[0] != 1:
    print("0")
    exit()
if 0 in num_array:
    print("0")
    exit()
for i in range(1, dmax+1):
    count *= num_array[i-1] ** num_array[i]
    count %= 998244353
print(count)

Solution (Python):
import collections
n = int(input())
d = [int(i) for i in input().split()]
ans = 0
if d[0] == 0:
    s = collections.Counter(d)
    ss = sorted(s.items())
    if ss[0][1] == 1:
        ans = 1
        for i in range(1,len(ss)):
            if ss[i][0] != ss[i-1][0] + 1:
                ans = 0
                break
            ans *= ss[i-1][1]**ss[i][1]
print(ans%998244353)

Solution (Python):
import math

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

ans = -1

d_count = [0] * (max(d)+1)
for i in range(n):
  d_count[d[i]] += 1

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

ans = 1
for i in range(1,len(d_count)-1):
  for j in range(d_count[i+1]):
    ans = ans * d_count[i]
    ans = ans % 998244353

ans = ans % 998244353

print(int(ans))

Solution (Python):
import collections
import operator

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

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))






if (D[0] == 0) and (D_dict_sorted[0][1] == 1) :
    ans = 1
    for i in range(len(D_dict_sorted)-1):
        if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]:
            ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
            if ans >= 998244353:
                ans = ans % 998244353
        else:
            ans = 0
else:
    ans = 0

print(ans)