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: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
# print(dic)
num = 1
n = 0
if (dic.get(0)==None)|(dic.get(0)>1):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num%998244353)

Submission status: Runtime Error

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？
# ケース12と13、完全にバグとしか思えないのですが?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

# もしかして：頂点1は必ず0？

n = int(input())
a = list(map(int, input().split()))
if a[0] != 0:
    print(0)
    exit()
a = sorted(a)
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1
if d[0] != 1
    print(0)
    exit()
MOD = 998244353

ans = 1
for i in range(1, a[-1] + 1):
    if i not in d:
        ans = 0
        break
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Runtime Error

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

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    D = LII()

   if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    mx = max(D)
    cnt = 1
    for i in range(1, mx+1):
        pre = D.count(i)
        post = D.count(i+1)
        cnt *= pre ** post
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

# if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1: もしかしてこれの最後の条件のせい？？？？？？？？？？？？
# いやおかしいだろ 0から最大値まで揃ってなきゃ構築できねぇだろうが
if a[0] != 0 or d[0] != 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
for i in range(2, a[-1] + 1):
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Runtime Error

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
# for i in range(2, a[-1] + 1):  なんでこれじゃだめなの？
for i in range(1, a[-1] + 1)
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

else:
    cnt = Counter(d)

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

if cnt[0] != 1:
    ans = 0
max_c = max(cnt)
for i in range(max_c + 1):
    if i not in cnt:
        ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
if d[0] != 0 or d[1] == 0:
    ans = 0
else:
    cnt = [0]*n
    for i in range(1, n):
        cnt[d[i]] += 1

ans = 1
for i in range(2, n):
    ans *= cnt[i-1]**cnt[i]
print(ans)

Submission status: Runtime Error

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

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

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

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

ans = 1
# for kx in range(1, max(D)+1):
for kx in range(2, len(tmp)+1):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    # p = cd[kx-1]
    # v = cd[kx]
    # print("{}^{}".format(p, v))
    while v > 0:
        ans *= p
        ans %= M
        v -= 1
# print(cd)

# for kx in range(1, max(D)+1):
#     ans *= pow(cd[kx-1], cd[kx],M)
#     ans %= M

print(ans)

Submission status: Runtime Error

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

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

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

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

ans = 1

import math
for kx in range(1, max(D)+1):
    ans *= math.pow(cd[kx-1], cd[kx],M)
    ans %= M

print(ans)

Submission status: Runtime Error

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

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

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

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

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
# print(cd)
for kx in range(1, len(tmp)-1):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    # ans *= p**v%M
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Runtime Error

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

    d_dict = collections.Counter(D)

    if D[0] != 0:
        print(0)
    else:
        cnt = 1
        for i, v in d_dict.items():
            if i >0 :
                if v > 2:
                    cnt *= (v-1)*(v-2)
                elif v == 2:
                    cnt *=  2
                elif v == 1:
                    cnt *= 1

    print(cnt)

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

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

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)
    an s %= mod

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

######INPUT######
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)]

######OUTPUT######
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()

#####Shorten#####
def DD(arg): return defaultdict(arg)


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

######Combination######
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

######Factorization######
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

#####MakeDivisors######
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

#####MakePrimes######
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

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

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

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

#####ChangeBase#####
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))))

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

#############
# Main Code #
#############
N = I()
A = IL()
M = max(A)
dic = DD(int)
for a in A:
  dic[a] += 1
if dic[0] != 1:
  print(-1)
else:
  ans = 1
  for i in range(M):
    ans *= pow(dic[i],dic[i+1])
print(ans)

Submission status: Runtime Error

Solution code:
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())
ans = 1
for i in range(l):
  ans *= d_dic[i]**d_dic[i+1]
  ans = ans%998244353
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)
maxi=max(d)

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

Submission status: Runtime Error

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

#print(d)

ans=1
if 0 not in d:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for num in d:
      if num==0:
        pass
      else:
        s= ((d[num-1])**d[num])%p
        ans = (ans * s)%p
    print(ans)

Submission status: Runtime Error

Solution code:
def combi(n,r):
  s = fac[n]
  t = fac[r]
  u = fac[n-r]
  ans = (s*pow(t,p-2,p)*pow(u,p-2,p) )%p
  return ans
  
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
di=dict(Counter(D))
p=998244353

fac=[1]
for i in range(1,N):
  fac.append( (fac[-1]*i)%p )

ans=1
for i,num in enumerate(sorted(di)):
  if i==0:
    if di[num]!=1:
      ans=0
      break
  else:    
    ans = (ans * combi(di[i-1]+di[i]-1,di[i-1]-1))%p
    ans = (ans * fac[ di[i-1] ]) %p
    print(i,num,di[num],combi(di[i-1]+di[i]-1,di[i-1]-1),fac[ di[i-1] ],ans)
  
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

ans = 0
if 0 in d:
    nums = sorted(collections.Counter(d).items())
    for num in nums:
        if num[0] == 0:
            ans += num[1]
        else:
            ans = ans * nums[num[0] - 1][1] ** num[1]

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
mod = 998244353
for k, v in c[1:]:
    if k - prev_k > 1:
        print(0)
        sys.exit()
    else:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev_k = k
        prev_v = v

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)
    c.sort()

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


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

print(solve(n, arr))

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n-1)]
for i in d:
  l[i] += 1
cou = 1
if 0 in l:
  a = l.index(0)
  if sum(l[a:])!=0:
    print(0)
    exit()
for i in range(n-2):
  if l[i+1]!=0:
    a = l[i]
    b = l[i+1]
    cou *= (a**b)%mod
print(cou%mod)

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n-1)]
for i in d:
  l[i] += 1
cou = 1
for i in range(n-2):
  if l[i+1]!=0:
    a = l[i]
    b = l[i+1]
    cou *= (a**b)%mod
  else:
    if l[i+1:].count(0)!=n-2-i:
      print(0)
      exit()
print(cou%mod)

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n-1)]
for i in d:
  l[i] += 1
cou = 1
for i in l:
  if i!=0:
    cou *= (i%mod)
print(cou%mod)

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
if d[0]!=0 or d[1:].count(0)!=0:
  print(0)
  exit()
l = [0 for i in range(n-1)]
for i in d:
  l[i] += 1
cou = 1
for i in l:
  cou *= (i%mod)
print(cou%mod)

Submission status: Runtime Error

Solution code:
def m():
    MOD = 998244353
    N = int(input())
    D = [0] + list(map(int, input().split()))
    if D[1] != 0:
        return 0
    tree = {1:1}
    for i in range(2, N + 1):
        if D[i] == 0: return 0
        tree[D[i] + 1] = tree[D[i] + 1] + 1 if tree.get(D[i] + 1, False) else 1

    height = len(tree.keys())+1
    cnt = 1
    for i in range(2, height):
        cnt = cnt * pow(tree[i-1], tree[i]) % MOD
    return cnt


print(m())

Submission status: Runtime Error

Solution code:
def m():
    MOD = 998244353
    N = int(input())
    D = [0] + list(map(int, input().split()))
    if D[1] != 0:
        return 0
    tree = {}
    for i in range(2, N + 1):
        if D[i] == 0: return 0
        tree[D[i] + 1] = tree[D[i] + 1] + 1 if tree.get(D[i] + 1, False) else 1

    height = len(tree.keys())+1
    cnt = 1
    for i in range(2, height):
        cnt = cnt * pow(tree[i-1], tree[i]) % MOD
    return cnt


print(m())

Submission status: Runtime Error

Solution code:
def m():
    MOD = 998244353
    N = int(input())
    D = [0] + list(map(int, input().split()))
    if D[1] != 0:
        return 0
    tree = {}
    for i in range(1, N + 1):
        tree[D[i] + 1] = tree[D[i] + 1] + 1 if tree.get(D[i] + 1, 0) else 1

    height = len(tree.keys())+1
    cnt = 1
    for i in range(2, height):
        cnt = cnt * pow(tree[i-1], tree[i]) % MOD
    return cnt


print(m())

Submission status: Runtime Error

Solution code:
import collections
import math
MOD = 998244353

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

ans = 1
if not d[0]  == 0:
    ans = 0
else:
    D = sorted(collections.Counter(d).most_common())
    for i in range(1, max(d)+1):
        ans = ans * pow(D[i-1][1], D[i][1], MOD)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict, deque
from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

MOD = 998244353

def solve():
    n = int(input())
    d = [int(x) for x in input().split()]
    f = [0] * n
    for e in d:
        f[e] += 1
    
    ok = f[0] == 1
    z = 0
    ans = 1
    for i in range(1, n):
        if (f[i] == 0): z = 1
        if (z and f[i]): ok = 0
        ans *= pow(f[i-1], f[i], MOD)
        ans %= MOD
    print(ans * ok)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import Counter

def cal(D,M):
    C = Counter(D)
    MC = C.most_common()
    MC = sort(key = lambda x:x[0])
    n = len(MC)
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    for i in range(n):
        if MC[i][0] != i:
            #深さiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1 or D[0] != 0:
        #1以外の根がある又は1が根になってない
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],M)
        output %= M
    return output

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

    ans = cal(D,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    dmax = max(D)
    cntr = [0] * (dmax + 1)
    for d in D: cntr[d] += 1  # カウンター

    if D[0] != 0: return 0  # 最初に入力される頂点1は距離0マスト
    if cntr[0] != 1: return 0  # 距離0が無い、または2つ以上、はおかしい

    ans = 1
    for i in range(1, dmax+1):
        if cntr[i] == 0: return 0  # カウント0だとつながらないのでNG
        ans = ans * (cntr[i-1][1] ** cntr[i][1]) % div
    print(ans)

nikkei19q_b()

Submission status: Runtime Error

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

M = max(D)
cnt = [0 for i in range(N - 1)]

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

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

for c in cnt[:M]:
    if c == 0:
        print(0)
        exit()

res = 1
MOD = 998244353
for i in range(1, M + 1):
    for c in range(cnt[i]):
        res = (res * cnt[i - 1]) % MOD

print(res)

Submission status: Runtime Error

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

M = max(D)
cnt = [0 for i in range(N - 1)]

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

for c in cnt[:M]:
    if c == 0:
        print(0)
        exit()

res = 1
MOD = 998244353
for i in range(1, M + 1):
    res = (res * cnt[i - 1] ** cnt[i]) % MOD

print(res)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
      print(0)
      exit()
dd=defaultdict(lambda:0)
for di in d:
      dd[di]+=1
if dd[0]>1:
      print(0)
      exit()
ans=1
for i in dd.keys():
      if i==0:
            continue
      ans*=(dd[i-1]**dd[i])%mod
print(ans%mod)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_b
# まず、本当に木を構築するモノではないだろう
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
mod = 998244353
MAX = max(nums)

c = Counter(nums)
if nums[0] != 0 or nums.count(0) != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, MAX + 1):
        ans = ans * pow(c.get(i - 1), c.get(i), mod) % mod
    ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # cnt[k] = v ... 深さkのノード数
    cnt = {}
    max_depth = 0
    for d in D:
        max_depth = max(max_depth, d)
        if d not in cnt:
            cnt[d] = 1
        else:
            cnt[d] += 1

    # 頂点1との距離が0になるノードは1つしか存在しない
    if 0 not in cnt:
        print(0)
        exit(0)
    elif cnt[0] > 1:
        print(0)
        exit(0)

    ans = 1
    MOD = 998244353
    for i in range(0, max_depth):
        if (i not in cnt) and (i + 1 not in cnt):
            ans = 0
            break
        ans *= cnt[i] ** cnt[i + 1]
        ans %= MOD

    print(ans)

Submission status: Runtime Error

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # cnt[k] = v ... 深さkのノード数
    cnt = {}
    max_depth = 0
    for d in D:
        max_depth = max(max_depth, d)
        if d not in cnt:
            cnt[d] = 1
        else:
            cnt[d] += 1

    # 頂点1との距離が0になるノードは1つしか存在しない
    if 0 not in cnt:
        print(0)
        exit(0)
    elif cnt[0] > 1:
        print(0)
        exit(0)

    ans = 1
    MOD = 998244353
    for i in range(0, max_depth):
        if i not in cnt:
            ans = 0
            break
        ans *= cnt[i] ** cnt[i + 1]
        ans %= MOD

    print(ans)

Submission status: Runtime Error

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

d=dict()
d[0]=0
for i in m:
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
    
a=max(m)
ans=1
for i in range(a):
  if i not in d:
    ans=0
    break
  if d[i]==0 or d[i+1]==0:
    ans=0
    break
  ans*=d[i]**d[i+1]
print(ans)

Submission status: Runtime Error

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

d=dict()
d[0]=0
for i in m:
  if i not in d:
    d[i]=1
  else:
    d[i]+=1
    
a=max(m)
ans=1
for i in range(a):
  ans*=d[i]**d[i+1]
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import groupby
inputs = open(0).readlines()

n = int(inputs[0])
*D, = map(int, inputs[1].split())
D.sort()
mod = 998244353

keys, nodes = [], [] 
for k, g in groupby(D):
    keys.append(k)
    nodes.append(len(list(g)))

if nodes[0] == 1 and all(i == k for i, k in enumerate(keys)):
    ans = 1
    for n0, n1 in zip(nodes, nodes[1:]):
        patterns.append(patterns[-1] * pow(n0, n1, mod) % mod)
        ans = ans * pow(n0, n1, mod) % mod
    print(ans)
else:
    print(0)

Submission status: Runtime Error

Solution code:
n = int(inputs[0])
n, *D = map(int, open(0).read().split())
D.sort()
mod = 998244353

keys = [k for k, g in groupby(D)]
nodes = [len(list(g)) for k, g in groupby(D)]

if nodes[0] != 1:
    print(0)
else:
    patterns = [1]
    for i, (k, n0, n1) in enumerate(zip(keys, nodes, nodes[1:])):
        if i != k:
            print(0)
            break
        patterns.append(patterns[i] * pow(n0, n1, mod) % mod)
    else:
        print(patterns[-1])

Submission status: Runtime Error

Solution code:
n = int(inputs[0])
*D, = map(int, inputs[1].split())
D.sort()
mod = 998244353

keys = [k for k, g in groupby(D)]
nodes = [len(list(g)) for k, g in groupby(D)]

if nodes[0] != 1:
    print(0)
else:
    patterns = [1]
    for i, (k, n0, n1) in enumerate(zip(keys, nodes, nodes[1:])):
        if i != k:
            print(0)
            break
        patterns.append(patterns[i] * pow(n0, n1, mod) % mod)
    else:
        print(patterns[-1])

Submission status: Runtime Error

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

if __name__=="__main__":
  main()

Submission status: Runtime Error

Solution code:
import sys
read = lambda: sys.stdin.readline().rstrip()

def counting_tree(N, D):
    tot = 1
    cnt = [0]*N
    # cnt = collections.Counter(D)
    for i in D:
        cnt[i]+=1
        
    for i in D[1:]:
        tot = tot*cnt[i-1]%998244353

    return tot if D[0]!=0 else 0

def main():
    
    N0 = int(read().split())
    D0 = tuple(map(int, read().split()))

    res = counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(max(D)+1)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 0 or C[0] != 1:
    ans = 0
    print(ans)
    exit()

ans = 1
for i in range(1,max(D)+1):
  ans *= C[i-1]**C[i]
  ans %= 998244353
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
sum = 1
a = list(map(int,input().split()))
for i in range(1,n):
  a[i]=a[i]-a[0]
  sum*=a[i]
print(math.sqrt(sum**2))

Submission status: Runtime Error

Solution code:
import collections

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

count_list = collections.Counter(D)

if count_list[0] != 1:
    print(0)
else:
    prod = 1
    for i in range(1, D_sorted[-1] + 1):
        if count_list[i] == 0:
            print(0)
            break
        prod *= count_list[i - 1]**count_list[i]

print(prod % 998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1

for i in range(1,n-1):
    if count[i-1] and not count[i] and count[i+1]:
        print(0)
        exit()

while count.count(0):
    count.remove(0)
ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
D={}
T=list(map(int,input().split()))
for i in range(N):
    if D.get(T[i],None)==None:
        D[T[i]]=1
    else:
        D[T[i]]+=1

Max=max(D)
Min=min(D)
Len=len(D)
Item=sorted((D.items()))
if(Item[i][0]!=i):
    print("0")
    exit()
ans=1
for i in range(1,Len):
    ans = (ans * (Item[i-1][1]**Item[i][1])) % 998244353
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * (maxD + 1)
ans=1

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

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif M<2:
    print(1)
    sys.exit()

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

for i in range(2,M+1):
        ans *= countlist[i-1]**countlist[i]

print(ans%998244353)

Submission status: Runtime Error

Solution code:
import sys
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * M
ans=1

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

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

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

for i in range(2,M+1):
    ans *= countlist[i-1]**countlist[i]

print(ans%998244353)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

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

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans)%998244353)

Submission status: Runtime Error

Solution code:

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

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

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans%998244353))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

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

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<max(D):
        ans=0
    else:
        break


print(int(ans%998244353))

Submission status: Runtime Error

Solution code:
def main():
    N = input()
    D_list = list(map(int, input().split()))

    maxD = max(D_list)
    count_nowD = D_list.count(0)
    lenD = len(count_nowD)

    if D_list.count(0) == 0:
        ans = 0
    elif count_nowD == lenD:
        ans = 1
    else:
        counter = 1
        ans = 1

        while counter <= maxD:
            count_beforeD = count_nowD
            count_nowD = D_list.count(counter)

            if(count_nowD == 0):
                ans = 0
                break

            ans = (ans * (count_beforeD ** count_nowD) % 998244353) % 998244353
            counter = counter + 1

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split(" ")))
repitition = len(d)-len(set(d))
print(max((n-1-reption)%998244353,0))

Submission status: Runtime Error

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

d.sort()
c = [0]
j = 0
for i in range(1, max(d)):
	tmp = 0
	 while d[j] == i:
	 	tmp += 1
	 	j += 1
	 c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1 and c.count(0) == 0:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print(ans%998244353)