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:
import sys
inputs = sys.stdin.readlines()
from collections import Counter

n = int(inputs[0])
D = list(map(int, inputs[1].split()))
MOD = 998244353
cnt = Counter(D)
if (D[0] != 0 or c[0] > 1):
    print(0)
else:
    ans = 1
    for i in range(1, max(D)+1):
        ans *= pow(cnt[i-1], cnt[i], MOD) % MOD
    print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
D_list = [int(s) for s in input().split(" ")]

res = 1
Dmax = max(D_list)
if (D_list.count(0) == 1) and (D_list(0) == 0):
    for i in range(0, Dmax):
        if D_list.count(i)!=0:
            if D_list.count(i)!=1:
                res *= D_list.count(i) ** D_list.count(i+1)
            else:
                continue
        else:
           res = 0
           break
else:
    res = 0

print(res % 998244353)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# メモ
# 連結無効グラフ　＝　全部が繋がっている

# N = int(input())
# D = list(map(int, input()))

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

JOSU = 998244353

anser = 0

deep = [-1] * (N + 1)
memo = [0] * N

# 各深さの数を求める
for i in range(N):
    if deep[D[i]] == -1:
        deep[D[i]] = 0
    deep[D[i]] += 1

def dfs(n, end, sum):
    if n == end:
        return sum
    elif deep[n + 1] == -1:
        return dfs(n + 1, end, sum)
    else:
        return dfs(n + 1, end, sum * deep[n] ** deep[n + 1])

if deep[0] != 1:
    print(0)
else:
    print(dfs(0, N, 1) % JOSU)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n1 = int(input()) - 1
d = list(map(int, input().strip().split()))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    max_path = max(d)
    flag = True
    v = [0 for i in range(max_path)]
    for i in d[1:]:
        v[i-1] += 1

    if 0 in v:
        flag = False

    if flag:
        num = 1
        hh = 1
        import math
        for h in range(len(v)):
            if hh == 1:
                pass
            elif v[h] == 1:
                num *= hh
            elif h < hh:
                num *= hh * (v[h] + 1)
            else:
                cnk = 0
                for i in range(hh):
                    cnk += math.factorial(hh)/math.factorial(h)/math.factorial(hh - h)

                num *= int(cnk)

            hh = v[h]

            num = num % mod

        print(num)

    else:
        print(0)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
D_count=sorted(Counter(D).items())
if D_count[0][0]!=0 or D_count[0][1]!=1:print(0);exit()
ans=1
for i in range(1,max(D)+1):
    ans *=D_count[i-1][1]**D_count[i][1]
    ans %=998244353
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
    ans = ans % mod
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans)

Submission status: Runtime Error

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

a = [0 for _ in range(N)]

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

ans = 0

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

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  else:
    if a[i] == 0:
      if cnt == N:
        break
      else:
        ans = 0
    else:
      temp = a[i-1] ** a[i]
      ans = (ans * temp ) % _mod

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if key == 0
        if dict[key] != 1:
            print(0)
            exit()       
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
num=[0]*n
for i in range(n):
       num(i)=d.count(i)
       ans=0
for i in range(n):
       if num(i)==0:
           break
       if i==0:
           ans+=1
       else:
           ans*=(num(i-1)**num(i))

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
top = max(D)
mod = 998244353

for i in range(N):
    l[D[i]] += 1
# print(*l)
ans = 1
for i in range(1, top+1):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
    if l[i] == 0:
        print(0)
        exit()
if D[0] != 0:
    ans = 0
if l[0] != 1:
    ans = 0
    

print(ans % mod)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int, input().split()))
dic = {i: d.count(i) for i in range(max(d)+1)}

if d[0] != 0:
    print(0)
else:
    if all(dic[i]>0 for i in range(max(d)+1)):
        res = 1
        for i in range(1, max(d)+1):
            res *= dic[i-1]**dic[i]
		print(res%998244353)
    else:
		print(0)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int, d.split()))
dic = {i: d.count(i) for i in range(max(d)+1)}

if d[0] != 0:
    print(0)
else:
    if all(dic[i]>0 for i in range(max(d)+1)):
        res = 1
        for i in range(1, max(d)+1):
            res *= dic[i-1]**dic[i]
		print(res%998244353)
    else:
		print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split())
num=[0]*n
for i in range(n):
       num(i)=d.count(i)
       ans=0
for i in range(n):
       if num(i)==0:
           break
       if i==0:
           ans+=1
       else:
           ans*=(num(i-1)**num(i))

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
    ans = ans%998244353

if c[0]!=1:
    ans=0
if D[0] != 0:
    ans = 0

# print(c)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int, input().split()))
b = 1
ans = 1
max = 0
dd=[0]*10**5
for i in d:
    dd[i]+=1
max = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, max+1):
        if dd[i] == 0:
            print(0)
            exit()
        if dd[i] == 1:
            ans *= b
        else:
            if b != 1:
                ans *= pow(b, dd[i], 998244353)
        b = dd[i]
    print(ans % 998244353)
else:
    print(0)

Submission status: Runtime Error

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1

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

zerofirst = L.find(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for a in A[:nonzerolast+1] :
  ans *= a

print(ans)

Submission status: Runtime Error

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

a = [0 for _ in range(N)]

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

ans = 0

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

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  else:
    if a[i] == 0:
      if cnt == n:
        break
      else:
        ans = 0
    else:
      temp = a[i-1] ** a[i]
      ans = (ans * temp ) % _mod

print(ans)

Submission status: Runtime Error

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
D=many_int()

num=998244353


dicts={}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True

if dicts[0]!=1:
    flg=True
        
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)

Submission status: Runtime Error

Solution code:
from sys import stdin
from collections import defaultdict

def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = defaultdict(int)
    for i in D:
        hash[i] += 1
    count = hash[0]
    for i in range(1, n):
        count *= hash[i-1] ** hash[i]
    print(count/998244353)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import defaultdict
MOD = 998244353

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

cnt = defaultdict(int)
m = 0
for i in range(n):
    cnt[d[i]] += 1
    m = max(d[i], m)

if d[0] != 0 or dd[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, m + 1):
        ans *= cnt[i - 1]**cnt[i]
        ans %= MOD

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353
B = [v for k, v in sorted(Counter(A).items())]
if A[0] != 0 or not all(A[1:]) or not all(m):
    print(0)
else:
    t, r = 1
    for b in B:
        t *= pow(r, b, MOD) % MOD
        r = b
    print(t)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

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

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

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

for j in range(k + 1):
    result *= pow_k(R[j], R[j + 1])

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

print(result % 998244353)

Submission status: Runtime Error

Solution code:
n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353
B = [v for k, v in sorted(Counter(A).items())]
if A[0] != 0 or not all(A[1:]) or not all(m):
    print(0)
else:
    t, r = 1
    for b in B:
        t *= pow(r, b, MOD) % MOD
        r = b
    print(t)

Submission status: Runtime Error

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    ans = ans * pow(num[i-1], num[i], 998244353)%998244353
    #ans*=num[i-1]**num[i]

if d[0]!=0 or d.count(0)=!1:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int,input().split()))
if d[0] != 0 or d.count(0) >= 2:
  print("0")
  break
else:
  ans = 1
  d.remove(0)
  for i in range(len(d)):
    ans *= d[i]
  print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
Ds = list(map(int, input().split()))
Dsi = [[Ds[i], i+1] for i in range(n)]
length = max(Ds) + 1
Pts = list()

Dsi = sorted(Dsi)
# print(Dsi, 'Dsi', 'Ds', Ds)


start = 0
Iss = list()
# print(length)
for i in range(length):
    Is = list()

    #距離がiであるようなヤツを探す
    for j in range(start, length+3):

        # print(i, j)
        if Dsi[j][0] == i:
            Is.append(Dsi[j][1])
        else:
            start = j
            break

    
    Iss.append(Is)

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)


for i in range(len(Iss)):
    if i == 0:
        Pts.append(math.factorial(len(Iss[i])))
    else:
        m = len(Iss[i])
        n = len(Iss[i-1])
        if m < n or m <= 1 or n <= 1:
            Pts.append(m**n * Pts[i-1])

            # print(i, Pts[i], 'bbb', m, n)
        else:
            st_p = permutations_count(m - 1, n-1) 
            r_p  = math.factorial(m) * math.factorial(n)

            Pts.append(st_p * r_p * Pts[i-1])
            
            # print(i, Pts[i], 'aaa', m, n)
print(Pts[-1])
# print('iss', Iss)

Submission status: Runtime Error

Solution code:
import math

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

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Runtime Error

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

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

cnt = Counter(d)

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

ans = 1
for i in d:
    if i != 0:
        ans *= cnt[i-1] % 998244353
print(and % 998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
d=[int(i) for i in input().split()]
if d[0]!=0:
    print(0)
else:
    ans=1
    m=max(d)
    cnt=[0]*(10**5+1)
    for i in d:
        cnt[i]+=1

    kaijo=[1]*(10**5+1)
    for i in range(1,m+1):
        kaijo[i]=(kaijo[i-1]%998244353)*(i%998244353)%998244353

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

Submission status: Runtime Error

Solution code:
n = int(input())
vertex_list = list(map(int, input().split()))
vertex_list.sort()
ans = 1
mark = 0
if vertex_list[0] != 0:
    print(0)
else:
    maxx = vertex_list[-1]
    for i in range(1,n):
        if vertex_list[i] is not 0 or vertex_list[1]-vertex_list[i-1]<2:
            ans *= vertex_list[i]
        else:
            mark =  1
    if mark = 0:
        print(ans)
    else:
        print(0)

Submission status: Runtime Error

Solution code:
ans=1
li2=[1] #最短経路iの頂点の個数を入れるリスト

if min(d)>0:
  print(0)
  exit()
else:
  for i in range(1,n):
    li=[ j for j in d if i == j ]
    length = len(li) #最短経路iの頂点の個数
    if length == 0:
      print(ans % 998244353)
      exit()
    else:
      ans = ans * (li2[-1] ** length) %998244353
      li2 += [length]
print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import math

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

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum *= n**dict[i]%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(max(D))]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    res *= new_l[n]**new_l[n+1]
    res %= 998244353
print(res%998244353)

Submission status: Runtime Error

Solution code:
import math

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

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = float(1)
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum *= n**dict[i]%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

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

    return K * x % 998244353

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



R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))
    A.remove(i + 1)

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

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

print(result % 998244353)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
#from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    ar = np.array(ar)
    tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])
    if ngflg:
        print("0")
    else:
        # ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        ans = 1
        for i in range(1,len(tmp)):
            ans *=  len(tmp[i -1]) ** len(tmp[i])

        print(ans % 998244353)
        # print(np.prod(ans_ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    ar = np.array(ar)
    tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])
    if ngflg:
        print("0")
    else:
        # ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        ans = 1
        for i in range(1,len(tmp)):
            ans *=  len(tmp[i -1]) ** len(tmp[i])

        print(ans % 998244353)
        # print(np.prod(ans_ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Runtime Error

Solution code:
import numpy as np
DIVISOR = 998244353
sys.setrecursionlimit(10000)

def Counting_of_trees(dist):
    if len(dist) == 1:
        if dist[0] == 0:
            return 1
        else:
            return 0

    arg = dist.argmax()
    dist_cuted = np.delete(dist, arg )

    cnt = np.count_nonzero(dist_cuted == dist.max() - 1)*Counting_of_trees(dist_cuted)
    return cnt

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

#print( Counting_of_trees(D) )
print( Counting_of_trees(D) % DIVISOR)

Submission status: Runtime Error

Solution code:
import numpy as np

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


def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

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

    return K * x % 998244353

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

k = max(A)

R = [1]
result = 1


for i in range(k):
    R.append(A.count(i + 1))
    A.remove(i + 1)

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

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

print(result % 998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
lists=list(map(int,input().split()))
anslist=[0 for i in range(n+1)]
anslist.append(0)
for j in lists:
    anslist[j]+=1
if anslist[0]!=1:
    print(0)
else:
    ans=1
    for j in range(n+1):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    if anslist[-1]1!=1:
      print(ans*2)

Submission status: Runtime Error

Solution code:
import numpy as np
DIVISOR = 998244353

def Counting_of_trees(dist):
    if len(dist) == 1:
        if dist[0] == 0:
            return 1
        else:
            return 0

    arg = dist.argmax()
    dist_cuted = np.delete(dist, arg )

    cnt = np.count_nonzero(dist_cuted == dist.max() - 1)*Counting_of_trees(dist_cuted)
    return cnt

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

#print( Counting_of_trees(D) )
print( Counting_of_trees(D) % DIVISOR)

Submission status: Runtime Error

Solution code:
import math

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

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = float(1)
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum *= n**dict[i]
        n = dict[i]

print(sum%998244353)

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np

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

if D[0] != 0:
    print(0)
elif sum(D == 0) != 1:
    print(0)
elifsum(np.diff(np.array(list(set(D)))) != 1):
    print(0)
else:
    D_counter = Counter(D)
    count = 1
    next = 1
    for i in range(1, max(D)+1):
        if i != next:
            print(0)
            break
        i = int(i)
        count = count * i**list(D_counter.values())[i]
        next += 1

print(int(count) % 998244353)

Submission status: Runtime Error

Solution code:

   from collections import Counter
n = int(input())
a = [int(i) for i in input().split()] 
if a[0]!=0:
    print ("0")
else:
    a = Counter(a)
    ans = 1
    for i in range(1,len(a)):   
        print(a[i])
        ans*=a[i]**a[i+1]
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
l=[0]*(max(d)+1)
ans=1
for i in range(max(d)):
  if not i in d:
    ans=0
    break
for i in range(1,n):
  l[d[i]] += 1
if l.index(0)+1:
  del l[l.index(0):]
for j in range(len(l)-1):
  ans *= l[j]**l[j+1]
print(ans%998244353)

Submission status: Runtime Error

Solution code:
def shisu(m,n):
    ans = 1
    for i in range(n):
        ans *= m
    return ans

inN = input()
N = int(inN)

D = []
count = []

for i in range(N):
    inD = input()
    numD = int(inD)
    D.append(numD)
    count.append(0)

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

ans = 1
if D[0]!=0 or count[0]!=1:
    ans=0
    print(ans)
    return
for i in range(N-1):
    if count[i]==0 and count[i+1]!=0:
        ans = 0
        return

for i in range(2,N):
    if count[i]!=0:
        s = shisu(count[i-1],count[i])
        ans *= s
        ans %= 998244353
        
print(ans)

Submission status: Runtime Error

Solution code:
mod = 998244353
N = int(input())
D = [int(i) for i in input().split()]
from collections import defaultdict as ddct
import numpy as np
def sum_matrix(Pre,Aft):
    matrix = np.zeros((Aft,Pre))
    matrix[0,:] = np.arange(Pre)+1
    matrix[:,0] = 1
    for pre in range(1,Pre):
        for aft in range(1,Aft):
            matrix[aft,pre] = matrix[aft-1,pre] + matrix[aft,pre-1]
    return int(matrix[Aft-1,Pre-1])
length_dict = ddct(int)
enable = True
for i,d in enumerate(D):
    if i==0 and d != 0:
        enable  *= False
        break
    elif  i==0 and d == 0:
        pass
    elif d == 0:
        enable  *= False
        break
        
    length_dict[d] += 1
ans = 1
for i in range(0,max(D)+1):
    if enable == False:
        break
    if i == 0:
        ans *= 1
    else:
        ans *= sum_matrix(length_dict[i-1],length_dict[i]) if length_dict[i-1] != 1 else length_dict[i]
        ans %=mod
print(ans) if enable == True else print(0)

Submission status: Runtime Error

Solution code:
# メモ
# 連結無効グラフ　＝　全部が繋がっている

# N = int(input())
# D = list(map(int, input()))

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

JOSU = 998244353

anser = 0

deep = [-1] * (N + 1)
deep[0] = 0
memo = [0] * N

# 各深さの数を求める
for i in range(N):
    if deep[D[i]] == -1:
        deep[D[i]] = 0
    deep[D[i]] += 1

def dfs(n, end, sum):
    if n == end:
        return sum
    elif deep[n + 1] == -1:
        return dfs(n + 1, end, sum)
    else:
        return dfs(n + 1, end, sum * deep[n] ** deep[n + 1])

print(dfs(0, N, 1) % JOSU)

Submission status: Runtime Error

Solution code:
# 入力
N = int(input())
D = [int(i) for i in list(input().split())]

result = 1
temp1 = 1
for i in range(max(D)+1):
    if D.count(i) == 0:
        print(0)
        exit()
    elif i == 1:
        result *= D.count(1)
        temp1 = D.count(1)
    else:
        temp2 = D.count(i)
        result *= temp1**temp2
        temp1 = temp2
    D = [j for j in D if i != j]
if result == 1:
    print(int(result%998244353))
else:
    print(int(result/2%998244353))

Submission status: Runtime Error

Solution code:
from collections import Counter

M = 998244353
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
r = 0
if a[0], c[0] == 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])

Submission status: Runtime Error

Solution code:
N=int(input())
D=list(map(int,input().split()))
DL=[]
Ddp=[]

def kumi(a,b):
    dp=[[1 for i in range(a)] for i in range(b+1)]
    for i in range(1,b+1):
        for j in range(1,a):
            dp[i][j] = dp[i-1][j]+dp[i][j-1]
    return max(max(dp))


if D[0]!=0:
    print(0)
else:
    maxD=max(D)
    for i in range(maxD+1):
        DL.append(D.count(i))
        for i in range(len(DL)-1):
            Ddp.append(kumi(DL[i],DL[i+1]))
        
    from operator import mul
    from functools import reduce
    print(DL[1]*(reduce(mul, Ddp)))

Submission status: Runtime Error

Solution code:
import math
from collections import Counter
N=int(input())
D=input().split()
T=[]
D_dict=Counter(D)
D_keys=list(D_dict.keys())
D_keyi=[int(n) for n in D_keys]
maxD=max(D_keyi)
D_keyi.sort()
ans=1
if D[0] != '0' or D_dict['0']!=1 or D_keyi != list(range(maxD+1)):
    print(0)
else:
    for i in range(maxD+1):
        T.append(D_dict[str(i)])
    for i in range(len(T)-1):
        ans=ans*(T[i]**T[i+1])
    print(mod(ans,998244353))

Submission status: Runtime Error

Solution code:
MOD = 998244353 
N = int(input())
D = [int(x) for x in input().split()]
lst = [0] * (N)
for d in D:
    lst[d] += 1
if (lst[0] == 1):
    pos0 = lst.index(0)
    if (len(set(lst[pos0+1:]))>1):
        print(0)
    else:
        ans = 1
        for i in range(N-1):
            ans *= pow(lst[i], lst[i+1], MOD)
        print(ans)
else:
    print(0)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if l[0] != 0:
  ans = 0
del l[0]
if l.count(0) != 0:
  ans = 0
else:
  l.remove(0)
  for i in range(max(l)-1):
    if l.count(i+1) == 0:
      ans = 0
      break
    else:
      if i == 0:
        a = 1
      else:
        a *= l.count(i)**l.count(i+1)
    ans = a % 998244353
print(ans)

Submission status: Runtime Error

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

if l[0] != 0:
  ans = 0
del l[0]
if l.count(0) != 0:
  ans = 0
l.remove(0)
else:
  for i in range(max(l)-1):
    if l.count(i+1) == 0:
      ans = 0
      break
    else:
      if i == 0:
        a = 1
      else:
        a *= l.count(i)**l.count(i+1)
    ans = a % 998244353
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
import numpy as np

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


if D[0] != 0:
    print(0)
elif sum(D == 0) != 1:
    print(0)
else:
    D_counter = Counter(D)
    count = 1
    next = 1
    for i in range(1, max(D)+1):
        if i != next:
            print(0)
            break
        i = int(i)
        count = count * i**list(D_counter.values())[i]
        next += 1
        
print(count % 998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
if not D[0]==0:
  ans=0
else:
  D.remove(0)
  ans = reduce(lambda x,y:x*y,D)
  ans=ans%998244353
print(ans)