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



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Accepted

Solution code:
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)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1

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

for key in C:
    if key >= 2:
        if memo2 + 1 != key: #道が途切れている場合はダメ
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod #modは和について閉じているため先にわる
        memo1 = C[key]
        memo2 = key
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()

C = Counter(D)
C = dict(sorted(C.items()))

memo1 = C[1]
memo2 = 1
ans = 1
for i in range(1,n):
    if D[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        if memo2 + 1 != key:
            print(0)
            exit()
        ans = (ans * (pow(memo1,C[key])))%998244353
        memo1 = C[key]
        memo2 = key
print(ans)

Submission status: Accepted

Solution code:
import sys
MOD = 998244353


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    e = [0]*n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans = ans*e[i-1] % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
MOD = 998244353


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    e = [0]*n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans *= e[i-1]
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import sys
MOD = 998244353


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    e = [0]*n
    for i in d:
        e[i] += 1
    ans = e[0]
    for i in d[1:]:
        ans *= e[i-1]
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
import sys
MOD = 998244353


def main():
    n, *d =  map(int, sys.stdin.buffer.read().split())
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in d[1:]:
            ans = ans*D[i-1]%MOD
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
MOD = 998244353

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

cnt = [0] * N
for i in range(N):
	cnt[D[i]] += 1

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

ans = 1
for i in range(1, max(D) + 1):
	ans = (ans * pow(cnt[i - 1], cnt[i], MOD)) % MOD
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
mod = 998244353
max_v = 0
lis = list(map(int, input().split()))

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

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

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

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

Submission status: Accepted

Solution code:
def pow_r(x,n,p):
  if n == 0:
    return 1
  if n % 2 == 0:
    return pow_r(x**2 % p, n//2, p)
  else:
    return x * pow_r(x**2 % p, n//2, p) % p
    

N = int(input())
Ds = list(map(int, input().split()))
memo = [0]*N
P = 998244353

for d in Ds:
  memo[d] += 1
  
if Ds[0] != 0 or memo[0] != 1:
  print(0)
  exit()
  
rlt = 1
cnt = 1

for i in range(1,N):
  if memo[i] > 0:
    rlt *= pow_r(memo[i-1], memo[i], P)
    rlt %= P
    cnt += memo[i]
  else:
    if cnt == N:
      print(rlt)
      exit()
    else:
      print(0)
      exit()
      
print(rlt)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    d = list(map(int,input().split()))
    mod = 998244353
    if d[0]!=0:
        print(0)
        return
    D = {0:1}
    for i in range(1,n):
        if d[i]==0:
            print(0)
            return
        if D.get(d[i]) == None:
            D[d[i]] = 1
        else:
            D[d[i]] += 1
    ans = 1
    if sorted(D.keys())[-1]!=len(D.keys())-1:
        print(0)
        return
    for k in range(1,len(D.keys())):
        ans *= pow(D[k-1],D[k],mod)
        ans = ans % mod
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353


def solve(n,d):
    if d[0] != 0:
        return 0
    dc = Counter(d)
    if dc[0] > 1:
        return 0
    res = 1
    k = 1
    dmax = max(d)
    while k <= dmax:
        res *= dc[k-1]**dc[k]
        res %= MOD
        k += 1
    return res


def main():
    N = int(input())
    d = list(map(int,input().split()))
    # N,M = map(int,input().split())
    print(solve(N,d))


if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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

    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    D = NLI()
    
    if D[0] != 0:
        print(0)
        sys.exit()
    else:
        Dc = sorted(collections.Counter(D).items())
        
        if Dc[0] != (0,1):
            print(0)
            sys.exit()
        elif Dc[1][0] != 1:
            print(0)
            sys.exit()
        else:
            ans = 1
            for i in range(2,len(Dc)):
                if Dc[i][0] != i:
                    print(0)
                    sys.exit()
                else:
                    ans = (ans * ((Dc[i-1][1] **Dc[i][1]))%MOD2)%MOD2
            print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = Counter(D)
if 0 not in D.keys():
    print(0)
    exit()
if D[0] > 1:
    print(0)
    exit()
max_key = max(D.keys())
cnt = [0] * (max_key + 1)
for i in range(0, max_key + 1):
    cnt[i] = D[i]
ans = 1
for i in range(1, len(cnt)):
    ans *= (cnt[i-1] ** cnt[i])
    ans %= 998244353
print(ans % 998244353)

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    a = Counter(d)
    ans = 1
    if a[0] > 1:
        print(0)
    else:
        for i in range(1, max(d)+1):
            ans *= a[i-1]**a[i]
            ans %= mod
        print(ans)

Submission status: Accepted

Solution code:
from collections import*
n=input()
a=list(map(int,input().split()))
d=dict(Counter(a))
mod=998244353
ans=a[0]==0 and d[0]==1
for i in d:
  if i==0:continue
  ans*=pow(d.get(i-1,0),d[i],mod)
  ans%=mod
print(ans)

Submission status: Accepted

Solution code:
import math
import sys

n=int(input())

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

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

lis=[0 for i in range(n)]

for i in range(n):
    lis[d[i]]+=1

for i in range(1,n-1):
    if lis[i]==0 and lis[i+1]!=0:
        print(0)
        sys.exit()
s=1

i=0
while i+1<=n-1 and lis[i+1]!=0:
    s=(s*pow(lis[i],lis[i+1],998244353))%998244353
    i+=1
print(s)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
    if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
        print(0)
        exit()
    l[d[i]]+=1
    mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
    ans *= t**l[i]
    t=l[i]

print(ans%998244353)

Submission status: Accepted

Solution code:
N = int( input() )
D = list ( int(x) for x in input().split() )

if D[0] != 0:
    ans = 0
else:
    Ds = [ 0 for i in range( max(D) + 1 ) ]

    for i in range( N ):
        Ds[ D[i] ] += 1

    ans = 1

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

            if ans == 0:
                break


print( ans % 998244353 )

Submission status: Accepted

Solution code:
import collections


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

    mod = 998244353

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

    cnt = collections.Counter(D)

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

    ans = 1

    for i in range(1, max(D)+1):
        if cnt[i - 1] == 1:
            continue
        ans *= cnt[i - 1] ** cnt[i] % mod
        ans %= mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, math
from functools import lru_cache
from collections import defaultdict
sys.setrecursionlimit(500000)
MOD = 10**9+7

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    D = list(mi())
    ans = 1

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

    dic = defaultdict(int)
    for i in range(N):
        dic[D[i]] += 1

    for i in range(1, N):
        ans *= dic[D[i]-1]
        ans %= 998244353

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:
        if total!=N:
            print(0)
            exit()
        else:break
    total+=B[i]
    ans*=(B[i-1]**B[i])
    ans%=mod

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
D = list(map(int, input().split()))
dp = [0] * N
for i in D:
  dp[i] += 1
ans = 1 if dp[0] == 1 and D[0] == 0 else 0
for i in range(1, N):
  ans *= dp[i-1] ** dp[i]
  ans %= 998244353
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
D = list(map(int, input().split()))
MOD = 998244353

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

if D[0] == 0 and cnt[0] == 1:
    res = 1
else:
    res = 0

for i in range(1, n):
    res *= pow(cnt[i - 1], cnt[i], MOD)
    res %= MOD

print(res)

Submission status: Accepted

Solution code:
p=998244353
n=int(input())
d=list(map(int,input().split()))
dep = [0]*n
for x in d:
  dep[x] += 1

ans = 1 if d[0]==0 and dep[0]==1 else 0
for i in range(1,n):
  ans *= (dep[i-1]%p) ** dep[i] % p
  ans %= p

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

input = sys.stdin.readline
P = 998244353


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

    count = defaultdict(int)
    for d in D:
        count[d] += 1

    if not(D[0] == 0 and count[0] == 1):
        print(0)
        exit()

    max_depth = max(count.keys())
    ans = 1
    for d in range(max_depth):
        ans = (ans * pow(count[d], count[d + 1], mod=P)) % P

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    import math
    n=int(input())
    d=list(map(int,input().split()))
    d2=[0]*n
    c=1
    for m in d:
        d2[m]+=1

    # print(d2)
    for i in range(1,n):
        c=c* pow(d2[i-1],d2[i],998244353)

    if d2[0]>1 or d[0]!=0:
        print(0)
    else:
        print(c % 998244353)
resolve()

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = LIST()
mod = 998244353

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

c = Counter(d)
counts = [0]*(max(d)+1)
for k, v in c.items():
    counts[k] = v
if counts[0] > 1:
    print(0)
    exit()
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i])
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
D=list(map(int,input().split()))
M=998244353

P=max(D)
L=[0]*(P+1)
for d in D:
    L[d]+=1

if not(L[0]==1 and D[0]==0):
    print(0)
    exit()

K=1
for i in range(P):
    K*=pow(L[i],L[i+1],M)
    K%=M
print(K)

Submission status: Accepted

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
counts = [0] * (max(d)+1)
for k, v in c.items():
    counts[k] = v
if counts[0] > 1:
    print(0)
    exit(0)
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i])
    ans %= mod

print(ans)

Submission status: Accepted

Solution code:

from collections import Counter

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

MOD = 998244353
ctr = Counter(X)

if X[0] == 0 and ctr[0] == 1:
    ans = 1
    for i in range(1, max(X) + 1):
        ans *= pow(ctr[i - 1], ctr[i], MOD)
        ans %= MOD
    print(ans)
else:
    print(0)

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
M = 998244353
from collections import Counter
c = Counter(d)
if d[0]!=0 or c[0]>=2:
    ans = 0
else:
    m = max(c.keys())
    ans = 1
    for i in range(1,m+1):
        if i not in c:
            ans = 0
            break
        ans *= pow(c[i-1], c[i], M)
        ans %= M
print(ans%M)

Submission status: Accepted

Solution code:
from collections import Counter

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

    mod = 998244353

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

    cnt = Counter(D)

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

    res = 1

    for i in range(1, max(D)+1):
        if cnt[i-1] == 1:
            continue
        res *= cnt[i-1]**cnt[i] %mod
        res %= mod
    
    print(res)

solve()

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353
MOD = 998244353

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

c = Counter(D)

ans = 1 * (not D[0]) * (c[0] == 1)
for i in range(1, max(c.keys())+1):
    ans *= pow(c[i-1], c[i], MOD)
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline


def mod_pow(x, n, mod=10**9 + 7) -> int:
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= mod
        x *= x
        x %= mod
        n //= 2

    return (K * x) % mod


MOD = 998244353

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

_max = max(D)

counts = defaultdict(int)

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

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

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

ans = 1
for i in range(1, _max + 1):
    if i not in counts.keys():
        print(0)
        sys.exit()
    elif i == 1:
        continue
    else:
        x = counts[i - 1]
        k = counts[i]
        ans = (ans * mod_pow(x, k, MOD)) % MOD

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= pow(p[i], p[i + 1], MOD)
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= pow(p[i], p[i + 1], mod=MOD)
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(max(D)):
        ans *= p[i] ** p[i + 1]
        ans %= MOD
        if ans == 0:
            break

    print(ans)

else:
    print(0)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

MOD = 998244353

p = defaultdict(int)
for d in D:
    p[d] += 1

if p[0] == 1 and D[0] == 0:
    ans = 1
    for i in range(N + 1):
        ans *= p[i] ** p[i + 1]
        ans %= MOD

    print(ans % MOD)

else:
    print(0)

Submission status: Accepted

Solution code:
def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

N = int(input())
D = list(map(int, input().split()))
dmax = max(D)
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
    cnt[d] += 1

if D[0] or cnt[0] != 1:
    print(0)
    exit()
ans = cnt[0]
for i in range(1, dmax + 1):
    now = my_pow(cnt[i - 1], cnt[i], MOD)
    ans *= now
    ans %= MOD
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter

n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(1, len(c)):
    if i != c[i][0]:
        ans = 0
        break
    ans *= pow(c[i - 1][1],c[i][1], 998244353)
print(ans%998244353)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import Counter
 
n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(1, len(c)):
    if i != c[i][0]:
        ans = 0
        break
    ans *= c[i - 1][1]**c[i][1]
    ans %= 998244353
print(ans)

Submission status: Accepted

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

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

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

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

ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
    if ans >= 998244353:
        ans %= 998244353
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys
MOD=998244353
N=int(input())
dlist=list(map(int,input().split()))

if dlist[0]!=0:
  print(0)
  sys.exit(0)
  
ddic=defaultdict(int)
for d in dlist:
  ddic[d]+=1
  
if ddic[0]!=1:
  print(0)
  sys.exit(0)
  
max_d=max(dlist)
answer=1
for d in range(1,max_d+1):
  if ddic[d]==0:
    print(0)
    sys.exit(0)
    
  term=pow(ddic[d-1],ddic[d],MOD)
  answer*=term
  answer%=MOD
  
print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print('0')
    exit()
counter = Counter(D)
if counter[0] != 1:
    print('0')
    exit()
counter = sorted(counter.items())
# print(counter)
keys = []
values = []
for i in range(len(counter)):
    keys.append(counter[i][0])
    values.append(counter[i][1])
for i in range(len(keys)):
    if i != keys[i]:
        print('0')
        exit()
ans = 1
for i in range(1, len(counter) - 1):
    ans *= pow(values[i], values[i + 1], mod)
    ans %= mod
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    set_d = sorted(list(set(D)))
    if D[0]!=0:
        print(0);exit()
    if set_d[-1]!=len(set_d)-1:
        print(0);exit()
    
    ans = 0
    pre = 1
    
    if 0 in node_cnt:
        if node_cnt[0]==1: 
            ans = 1
    for k,v in sorted(node_cnt.items()):
        ans*=pow(pre,v)
        ans%=mod
        pre = v
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
*D,=map(int,input().split())
M=max(D)
from collections import*
C=Counter(D)

ans=1
now=C[1]
for i in range(2,M+1):
    ans*=pow(now,C[i],998244353)
    ans%=998244353
    now=C[i]

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

Submission status: Accepted

Solution code:
import collections

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

ans = 0
c = collections.Counter(d)
if c[0] == 1 and d[0] == 0:
    ans = 1
for i in range(1,max(d)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= pow(c[i-1],c[i],mod)
    ans %= mod
print(ans%mod)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


import collections


# In[2]:


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


# In[7]:


mod = 998244353
if D[0] == 0:
    ans = 1
    tmp = 1
    cnt = 0
    for i,x in sorted(collections.Counter(D[1:]).items(), key=lambda x:x[0]):
        if i == cnt+1:
            ans *= (tmp**x)%mod
            tmp = x
            cnt += 1
        else:
            ans = 0
            break
    print(ans%mod)
else:
    print(0)


# In[ ]:

Submission status: Accepted

Solution code:
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
dic=Counter(d)
MOD=998244353
ans=1
if d[0]!=0 or dic[0]!=1: print(0)
else:
    for i in range(1,max(dic.keys())+1):
        ans*=pow(dic[i-1],dic[i],MOD)
        ans%=MOD
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if D[0] != 0:
    print(0)
    exit(0)
# 0が1つでない場合の答えは0になる
if c[0] != 1:
    print(0)
    exit(0)

MOD = 998244353
cnt = 1
for i in range(1, max(D)+1):
    cnt *= pow(c[i-1], c[i], MOD)
print(cnt % MOD)

Submission status: Accepted

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline
m=998244353

N=int(input())
D=list(map(int,input().split()))
Dc = collections.Counter(D)
count=1
if D[0] !=0 or Dc[0]>1:
    print(0)
else:
    for i in range(1,max(Dc.keys())+1):
        count *=pow(Dc[i-1],Dc[i],m)
    print(count%m)

Submission status: Accepted

Solution code:
# import math
# import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
# dcnt = collections.Counter(d)
cnt = [0]*10**5
mv = max(d)
for i in d:
    cnt[i] += 1
# print(cnt[:mv+1]
if d[0] != 0:
    print(0)
    exit()
ans = 1
for i, v in enumerate(cnt[:mv+1]):
    # print(i, v)
    if i == 0:
        if v == 1:
            continue
        else:
            print(0)
            exit()
    else:
        if v == 0:
            print(0)
            exit()
        else:
            c = cnt[i-1]**v % mod
            ans *= c
            ans %= mod
            # print(ans, c)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
count = [0]*n
ans = 1
flag = True
for d in map(int,input().split()):
    if flag:
        if d!=0:
            print(0)
            exit()
        flag = False
    count[d] += 1
for i in range(1,n):
    if count[0]!=1:
        ans = 0
        break
    if count[i]==0:
        if any(k!=0 for k in count[i:]):
            ans = 0
        break
    ans *= (count[i-1]**count[i])%998244353
    
print(ans%998244353)

Submission status: Accepted

Solution code:
from collections import Counter

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

mod=998244353

c=Counter(d)
max_key=max(d)

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

ans=1
patterns=1
for i in range(max_key+1):
  p_num=c[i]
  ans*=patterns**p_num
  ans%=mod
  patterns=p_num

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
d=lnii()

mod=998244353

c=Counter(d)
max_key=max(d)

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

ans=1
patterns=1
for i in range(max_key+1):
  p_num=c[i]
  ans*=patterns**p_num
  ans%=mod
  patterns=p_num

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)
MOD = 998244353
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
store = [0 for _ in range(MAX+1)]

for x in A:
  store[x] += 1

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

ans = 1
for i in range(MAX):
  ans = ans*pow(store[i],store[i+1],MOD)
print(ans%MOD)

Submission status: Accepted

Solution code:
p=998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
D = list(map(int,input().split()))
D.insert(0,0)
C = {i:0 for i in range(N)}
for i in range(1,N+1):
    C[D[i]] += 1
if C[0]!=1 or D[1]!=0:
    cnt = 0
else:
    ind = 0
    for i in range(N):
        if C[i]==0:
            ind = i
            break
    flag = 0
    if ind>0:
        for i in range(ind+1,N):
            if C[i]>0:
                flag = 1
                break
    if flag==1:
        cnt = 0
    else:
        C = sorted(list(C.items()),key=lambda x:x[0])
        cnt = 1
        for i in range(1,N):
            if C[i][1]==0:break
            c0 = C[i-1][1]
            c1 = C[i][1]
            cnt = (cnt*(pow(c0,c1)))%p
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
dl = list(map(int, input().split()))

MOD = 998244353
ans = 0
d_comb = [0]*n

if dl[0] == 0:
    ans = 1
    d_comb[0] = 1
else:
    print(0)
    exit()

dl.sort()
if n == 1:
    print(1)
    exit()
elif dl[1] == 0:
    print(0)
    exit()

for d in dl[1:]:
    ans *= d_comb[d-1]
    d_comb[d] += 1
    ans %= MOD

print(ans)

Submission status: Accepted

Solution code:
import sys
n=int(input())
ans=[0]*(n+1)
MOD=998244353
a=list(map(int,input().split()))
if a[0]!=0:
  print(0)
  sys.exit()
for i in range(n):
  ans[a[i]]+=1
if ans[0]!=1:
  print(0)
  sys.exit()
fin=1
for i in range(1,max(a)+1):
  fin=(fin*pow(ans[i-1],ans[i],MOD))%MOD
print(fin)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

c = Counter(Ds)
if Ds[0]!=0:
    print(0)
elif c[0]>1:
    print(0)
else:
    ans = 1
    for i in range(1, N):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353


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


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


ans = 1
C = Counter(D)
for k, v in C.items():
    if k == 0:
        continue
    ans *= pow(C[k - 1], v, MOD)
    ans %= MOD

print(ans % MOD)

Submission status: Accepted

Solution code:
N = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()
from collections import Counter
ctr = Counter(D)
if ctr[0] > 1:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

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


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