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

def main():
    N = int(input())
    D = map(lambda i: int(i), input().split(' '))
    answer = 1
    ary = [0] * (N - 1)

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

    # 続いてなかったらNG
    zero = False
    for i in range(len(ary)):
        if ary[i] != 0 and zero is True:
            print(0)
            sys.exit()
        if ary[i] == 0 and zero is False:
            zero = True
            
    for i in range(len(ary)):
        if i == 0:
            if ary[i] != 1:
                print(0)
                sys.exit()
        else:
            answer = (answer * (ary[i - 1] ** ary[i])) % 998244353
    print(answer)

main()

Submission status: Runtime Error

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

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

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


ans = 0
for i in range(N-1):
  if i == 0:
    ans += a[i]
  else:
    if a[i] == 0:
      pass
    else:
      ans = (ans * a[i]) % 998244353

print(ans)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
dl=list(map(int,input().split()))
MOD=998244353
if dl[0]>0:
    print(0)
    exit()
dist=[0]*(n-1)
for d in dl:
    dist[d]+=1
if dist[0]!=1:
    print(0)
    exit()
ans=1
flg=False
for i in range(1,n-1):
    if dist[i]>0:
        if flg:
            ans=0
            break
        else:
            ans*=dist[i-1]**dist[i]%MOD
    else:
        flg=True
print(ans%MOD)

Submission status: Runtime Error

Solution code:
if __name__ == "__main__":
    mod = 998244353

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

    if d[0] > 0:
        print('0')
        exit()

    d.sort()
    d.pop(0)
    if d[0] == 0:
        print('0')
        exit()

    tmp = 1
    ans = 1
    max_num = max(d)
    dic = dict()
    for i in range(n-1):
        if d[i] in dic:
            dic[d[i]] += 1
        else:
            dic[d[i]] = 1

    for i in range(1, max_num+1):
        count = dic[i]
        if count == 0:
            print('0')
            exit()
        ans *= tmp ** count
        ans %= mod
        tmp = count

    print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np
from functools import reduce

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

D_seq_max = max(D_seq)

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

N_list = [1]
if((judge_set == D_seq_set)or(D_seq[0]==0)):
    for i in range(D_seq_max):
        N_list.append(D_seq.count(i+1))
    counts = reduce(pow, N_list)
    for i in range(len(N_list)-1):
        counts *= pow(N_list[i], N_list[i+1])
    if(counts < 998244353):    
        print(counts)
    else:
        print(int(counts/998244353))
        
else:
    print(0)

Submission status: Runtime Error

Solution code:
n=int(input())
d=list(map(int,input().split()))
c=[0]*n
ans=0
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(2,n-1):
    if c[j+1]!=0 and c[j]==0:
      ans=0
      break      
    elif c[j]==0 and c[j+1]==0:
      ans+=0
    else:
      ans*=c[j]**c[j-1]
      
  if c[n-2]==0　and c[n-1]!=0:
      ans=0
  elif c[n-2]==0 and c[n-1]==0:
    ans+=0
  elif:c[n-1]==0:
    ans+=0
  else:
    ans*=c[n-1]**c[n-2]
      
  print(int(ans%998244353))

Submission status: Runtime Error

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

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

print(ans)

Submission status: Runtime Error

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

# B が小さいほど制約が大きいのでBが小さいものからみる
C = sorted(zip(A, B), key=lambda x: x[1])
A, B = map(list, zip(*C))

ans = 0
for i in range(N):
    if ans > N - 2:
        print("No")
        exit()
    if (A[i] > B[i]):
        if [k for k in A[i + 1:] if k <= B[i]]:
            j = A[i + 1:].index(max([k for k in A[i + 1:] if k <= B[i]]))
            A[i], A[j] = A[j], A[i]
            ans += 1
        else:
            print("No")
            exit()

print("Yes")

Submission status: Runtime Error

Solution code:
import collections
import operator

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

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

if not D[0] != 0:
    ans = 1
    for i in range(int(max(D))):
        ans *= D_dict_sorted[i][1] ** D_dict_sorted[i+1][1]
        if ans >= 998244353:
            ans = ans % 998244353
else:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
import collections
import sys
sys.setrecursionlimit(100000)
nCr = {}


def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


def main():
    n = int(input())
    d_list = list(map(int, input().split()))
    
    # d_list.sort()
    d_max = max(d_list)
    d_col = collections.Counter(d_list)
    
    ans = 1
    for i in range(d_max, 0, -1):
        d_col_i = d_col.get(i, 0)
        temp_cmb = 0
        for j in range(d_col_i, (d_col_i // 2), -1):
            temp = cmb(d_col_i, j)
            temp_cmb += temp
        temp_ans = d_col.get(i - 1, 0) * temp_cmb
        ans *= temp_ans
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
N = int(input())
D = [int(x) for x in input().split()]

num = [0] * 10000

maxd = 0
for d in D:
    num[d] += 1
    maxd = max(d, maxd)

if D[0] != 0 or num[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, maxd):
        ans *= int(math.pow(num[i], num[i+1])) % 998244353
        if ans == 0:
            break
print(ans)

Submission status: Runtime Error

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

waru = 998244353

dic = {}
dic2 = {}

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

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

if 0 in dic2:
    pass
else:
    print(0)
    exit(0)

l = []

for i in range(1, len(dic2.items()) -1):
    l.append(dic2[i] ** dic2[i+1])

#print(l)

r = 1
for x in l:
    r *= x
d, m = divmod(r, waru)
print(m)

Submission status: Runtime Error

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
k = [1]*10005
out = 0
if d[0] != 0:
    out = 1
now = 1
for i in range(2,n):
    if d[i-1] == d[i]:
        k[now] += 1
    else:
        now += 1
c = 1
for i in range(now):
    c *= k[i]**k[i+1]
    c %= 998244353
if out:
    print(0)
else:
    print(c)

Submission status: Runtime Error

Solution code:
from collections import Counter 
n = int(input())
d = list(map(int,input().split()))
c = Counter(d)
ans = 1
if c[0]==1:
  x = c[0]
  for a,b in c.items():
    y = b
    ans*=x**y
    x = b
else:
  ans = 0
print(ans/998244353)

Submission status: Runtime Error

Solution code:
import math

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

ans = -1

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

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

ans = 1
for i in range(1,len(d_count)-1):
  ans = ans *  math.pow(d_count[i], d_count[i+1])

ans = ans % 998244353

print(int(ans))

Submission status: Runtime Error

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

if min(Ds)!=0 or Ds.count(0)!=1:
    print(0)
else:
    Ans=[0]*(max(Ds)+1)
    Ans[0]=1
    for i in range(1, max(Ds)+1):
        Ans[i]=(Ans[i-1]*(Ds.count(i-1)**Ds.count(i)))

    print(Ans[max(Ds)])%998244353

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
import math

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

ans = 0
flag = 0

dx = collections.Counter(d)

if(dx[0] != 1):
    flag = 1

ds = list(set(d))
if(len(ds) != ds[-1]+1):
    flag = 1
        
if(flag == 0):
    ans += 1
    for i in range(len(d)-1):
        ans *= math.pow(dx[i],dx[i+1])

print(round(ans)%998244353)

Submission status: Runtime Error

Solution code:
import numpy as np


N = int(input())
D = input().split().sort()

D_list = list(set(D))
D_count = []
for d_ in D_list:
    D_count.append(D.count(d_))
if (D_list[-1] != len(D_list) - 1) | (D_count[0] != 1):
    print(0)
else:
    ans = 1
    D_count = np.array(D_count)
    D_ = D_count[:-1]**D_count[1:]
    print(D_.prod() % 998244353)

Submission status: Runtime Error

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

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

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


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

print(ans)

Submission status: Runtime Error

Solution code:
from decimal import *
import sys
n = int(input())
array = list(map(int, input().split()))
dic = {0:0}
for i in range(n):
    key = array[i]
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
j = 1
count = Decimal(1)
while j in dic:
    if j-1 in dic:
        count *= Decimal(dic[j-1])**Decimal(dic[j])
        count %= Decimal(998244353)
        j += 1
    else:
        print(0)
        exit()
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial as fact
from collections import Counter

N = int( input() )
tree = list( map( int, input().split() ) )
ans = 1
if tree[0] != 0:
    print(0)
else:
    c = Counter(tree)
    if c[0] != 1:
        print(0)
    else:
        a = 1
        for i in range( 1,len(c)):
            t = c[i]
            if a == 1:
                ans *= t
            else:
                ans *= int( a ** t / fact(a) )
            a = t 
        print(ans)

Submission status: Runtime Error

Solution code:
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

count_dict = sorted(Counter(D).items(), key=lambda x:x[0])
count_list = list(dict(count_dict).values())

if len(count_list) == max(D) + 1 and not 0 in D[1:]:
    ans = 1
    for i in range(len(count_list)):
        if i == 0:
            if D[0] == 0:
                pass
            else:
                ans = 0
                break
        else:
            ans *= power_func(count_list[i - 1], count_list[i], p)
else:
    ans = 0

ans %= p
print(ans)

Submission status: Runtime Error

Solution code:
import math
import numpy as np

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

D_seq_max = max(D_seq)

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

N_list = []
if((judge_set == D_seq_set)or(D_seq[0]==0)):
    for i in range(D_seq_max):
        N_list.append(D_seq.count(i+1))
    counts = 1
    for i in range(len(N_list)-1):
        counts *= pow(N_list[i], N_list[i+1])
    if(counts < 998244353):    
        print(counts)
    else:
        print(int(counts/998244353))
        
else:
    print(0)

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
A = [int(x) for x in input().split()]

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    elif n==1:
        print(1)
    else:
        ans = 1
        for i in range(1,n):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)

Submission status: Runtime Error

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

max_vertex = max(l)
ll = []
l=sorted(l)
l.append('end')
c=1
for i in range(1, n):
    if l[i] != l[i+1]:
        if c == 0:
            print(0)
            exit();
        ll.append(c)
        c = 0
    c+=1
   
count = 1
for i in range(1, max_vertex):
    tmp = ll[i-1]
    count *= pow(tmp, ll[i])
print(count%998244353)

Submission status: Runtime Error

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

max_vertex = max(l)
ll = []
l=sorted(l)
l.append('end')
c=1
for i in range(1, n):
    if l[i] != l[i+1]:
        ll.append(c)
        c = 0
    c+=1
   
count = 1
for i in range(1, max_vertex):
    tmp = ll[i-1]
    count *= pow(tmp, ll[i])
print(count%998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input()))
answer = 1

if D[0] != 0:
  print('0')
elif max(D) == 1:
  print('1')
else:
  for i in range(1, max(D)):
    answer *= D.count(i) ** D.count(i + 1)
  print(answer)

Submission status: Runtime Error

Solution code:
import sys

def main():
    N = int(input())
    D = map(lambda i: int(i), input().split(' '))
    maximum = 0
    ary = [0] * (N - 1)
    for d in D:
        ary[d] = ary[d] + 1
        if maximum < d:
            maximum = d
    answer = 1
    for i in range(maximum + 1):
        if i == 0:
            if ary[i] != 1:
                print(0)
                sys.exit()
        elif ary[i] == 0:
            print(0)
            sys.exit()
        else:
            answer = (answer * (ary[i - 1] ** ary[i])) % 998244353
    print(answer)

main()

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
D = list(map(int, input().split()))
is_first_zero = True
if D[0] != 0:
    is_first_zero = False
if is_first_zero:
    c = sorted(collections.Counter(D).items(), key=lambda x:x[0])
    #print(c)
    for index, i in enumerate(c):
        ind = i[0]
        num = i[1]
        if ind == 0:
            if num != 1:
                is_first_zero = False
                break
        else:
            if ind != pre_ind + 1:
                is_first_zero = False
                break
            else:
                if index == 2:
                    res = pre_num ** num
                elif index > 2:
                    res = res * (pre_num ** num)
                #print(res)
        pre_ind = ind
        pre_num = num
                
if is_first_zero:
    print(res % 998244353)
else:
    print("0")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

def main():
    N = int(input())
    D = map(lambda i: int(i), input().split(' '))
    maximum = 0
    ary = [0] * (N - 1)
    for d in D:
        ary[d] = ary[d] + 1
        if maximum < d:
            maximum = d
    answer = 1
    for i in range(maximum + 1):
        if i == 0:
            if ary[i] != 1:
                print(0)
                sys.exit()
        elif ary[i] == 0:
            print(0)
            sys.exit()
        else:
            answer = (answer * (ary[i - 1] ** ary[i])) // 998244353
    print(answer)

main()

Submission status: Runtime Error

Solution code:
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
if cnt[0]!=1:
  print(0)
  exit()
  
ans = 1
for i in range(len(dict(cnt))-1):
  val_1 = cnt[i]
  val_2 = cnt[i+1]
  ans *= (val_1**val_2)%MOD

print(ans%MOD)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import math
 
def nCr(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
 
def solve(n, d):
    if d[0] != 0:
        print(0)
        return
 
    count = {}
    pre = 0
    for i, d_i in enumerate(sorted(d)):
        if d_i != pre and d_i + 1 == pre:
            print(0)
            return
 
        if d_i not in count:
            count[d_i] = 0
        count[d_i] += 1
 
    ans = 1
    pre = 1
    for i, c in count.items():
        if i == 0:
            continue
 
        ans *= (nCr(pre, 1) ** c)
        ans = ans % 998244353
        pre = c
 
    print(ans)
 
if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    d = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, d)

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
A = [int(x) for x in input().split()]

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    else:
        ans = 1
        for i in range(1,n):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)

Submission status: Runtime Error

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

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

ans=1

a=[0]*n

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

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

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])
    ans%=998244353

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import math

N = int(sys.stdin.readline())

D = list(map(int, sys.stdin.readline().split()))

mod = 998244353

unique_list = list(set(D))
count = 0
for i in unique_list:
    if i != count:
        ans = 0
        print(ans)
        sys.exit()
    count += 1

previous = 0
temp_ans = 0
for i in range(len(unique_list)):
    temp_count = D.count(i)
    if i == 0 and temp_count > 1:
        ans = 0
        print(ans)
        sys.exit()
    if i == 1:
        temp_ans = 1
    else:
        temp_ans = temp_ans * math.pow(previous, temp_count) % mod
    previous = temp_count

print(int(temp_ans))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
D = [int(x) for x in input().split()]

num = [0] * 10000

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

if D[0] != 0 or num[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, max(num)):
        ans *= int(math.pow(num[i], num[i+1])) % 998244353
        if ans == 0:
            break
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math

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

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

    count = {}
    pre = 0
    for i, d_i in enumerate(sorted(d)):
        if d_i != pre and d_i + 1 == pre:
            print(0)
            return

        if d_i not in count:
            count[d_i] = 0
        count[d_i] += 1

    ans = 1
    pre = 1
    for i, c in count.items():
        if i == 0:
            continue

        ans *= (nCr(pre, 1) ** c)
        ans = ans % 998244353
        pre = c

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    d = map(int, sys.stdin.readline().strip().split(" "))
    solve(n, d)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
D = [int(x) for x in input().split()]

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

num = [0] * 10000

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

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

ans = 1
for i in range(1, max(num)):
    ans *= int(math.pow(num[i], num[i+1])) % 998244353
    if ans == 0:
        print(0)
        exit()
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
ld=list(map(int,input().split()))
def modpow(a,n,p):#a^n mod p
    res=1
    while n>0:
        if n&1:#１とのビット論理積が１、つまり奇数
            res=res*a%p
        a=a*a%p
        n>>=1
        #ビットの右シフト_2進数表記のnを小数点を固定して右に１桁ずらす_１桁小さくなる
    return res
if ld[0]!=0:
    print(0)

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

Submission status: Runtime Error

Solution code:
BIGMOD = 998244353

def modPow(x,n):
    ans = 1
    while n >= 1:
        if bin( n & 1)==bin(1):
            ans = (ans*x) % BIGMOD
        x = x * x % BIGMOD
        n = n>>1
    return ans % BIGMOD

def modFact(N):
    fact = []
    fact.append(1) #0! = 1
    for i in range(1,N+1):
        a = fact[i-1]*i % BIGMOD
        fact.append(a)
    return fact

def modInvFact(fact):
    invFact = []
    for i in range(1,N+2):
        a = modPow(fact[i-1],BIGMOD-2)
        invFact.append(a)
    return invFact

def modPlus(a,b):
    return (a + b) % BIGMOD

def modMinus(a,b):
    if a-b >= 0:
        return (a - b) % BIGMOD
    else:
        return (a - b + BIGMOD)
    
def modMulti(a,b):
    return a * b % BIGMOD

# fact(n),invFact(r),invFact(n-r)
def nCr(fact,invFact,n,r):
    return (fact[n] * invFact[r] * invFact[n-r] ) %BIGMOD

def nPr(fact,invFact,n,r):
    return(fact[n] * invFact[r])%BIGMOD

def fact(num):
    ans = 1
    for i in range(1,num+1):
        ans = ans*i%BIGMOD
    return ans

import collections

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

S = list(set(D))
S.sort()
if S[0]==0:
    S.pop(0)
ans = 1
before = 0
before_i = 0
c = collections.ounter(D)
for i in S:
    if i == 1:
        before = c[i]
        before_i = i
        continue
    ans = ans*modPow(before,c[i])%BIGMOD
    before = c[i]
    if i - before_i!=1:
        ans = 0
    before_i = i
if D[0] >0:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import math
import collections

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

if d[0]!=0:
  print(0)
  exit()
  
#print(n,d)
cnt = dict(collections.Counter(d))

ans = 1
for i in range(len(dict(cnt))-1):
  val_1 = cnt[i]
  val_2 = cnt[i+1]
  ans *= (val_1**val_2)%MOD

print(ans%MOD)

Submission status: Runtime Error

Solution code:
temp = list(map(int, input().split()))
N = temp[0]
Ds = temp[1:]

counter = map( (lambda x: 0), range(N) )

for distance in Ds:
    counter[ distance ] += 1   

if N == 1:
    if counter[0] == 1:
        result = 1
    else:
        result = 0
else:
    if counter[0] != 1 :
        result = 0
    else:
        result = counter[1]
    
if N > 2:
    for distance in range(2,N):
        temp = pow( counter[distance-1], counter[distance] ) // 998244353
        result = (result * temp) // 998244353

print(result)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N = int(input())
D = map(int, raw_input().split())

sum = 1
num_pre = 0
for i in range(1,N):
    num_i = D.count(i)
    if num_i == 0:
        break
#    print "*** "                                                                                      
#    print num_i, num_pre                                                                              
    c = comb(num_i + num_pre - 1, num_i, exact=True)
    if c ==0:
        c= 1
    sum = sum*c
    num_pre = num_i

print sum

Submission status: Runtime Error

Solution code:
import math
import collections

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

if d[0]!=0:
  print(0)
  exit()
  
#print(n,d)
cnt = dict(collections.Counter(d))

ans = 1
for i in range(len(dict(cnt))-1):
  val_1 = cnt[i]
  val_2 = cnt[i+1]
  ans *= val_1**val_2

print(ans%MOD)

Submission status: Runtime Error

Solution code:
#B
import collections

N = int(input())
D = list(map(int, input().split()))
is_first_zero = True
if D[0] != 0:
    is_first_zero = False
if is_first_zero:
    c = sorted(collections.Counter(D).items(), key=lambda x:x[0])
    #print(c)
    for index, i in enumerate(c):
        ind = i[0]
        num = i[1]
        if ind == 0:
            if num != 1:
                is_first_zero = False
                break
        else:
            if ind != pre_ind + 1:
                is_first_zero = False
                break
            else:
                if index == 2:
                    res = pre_num ** num
                elif index > 2:
                    res = res * (pre_num ** num)
                #print(res)
        pre_ind = ind
        pre_num = num
                
if is_first_zero:
    print(res)
else:
    print("0")

Submission status: Runtime Error

Solution code:
M = 998244353

N = int(input())
d_list = list(map(int, input().split()))
d_list.sort()

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f = (f * i) % M
	return f

def check():
	d = d_list.pop(0)
	if d != 0:
		print(0)
	else:
		if d_list[0] == 0:
			print(0)
		else:
			d_counts = [1]
			prev_d = 0
			for d in d_list:
				if prev_d == d:
					d_counts[prev_d] += 1
				elif prev_d + 1 == d:
					d_counts.append(1)
					prev_d = d
				else:
					print(0)
					return
		count = 1
		prev_d = d_counts.pop(0)
		for d in d_counts:
			count = (count * pow(prev_d, d)) % M
			prev_d = d
		print(count)

check()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=list(map(int,input().split()))

if temp[0]==0:
    print(0)
    exit()

ans=1
for i in range(2,len(temp)):
    #print(ans)
    ans=ans*temp[i-1]**temp[i]
print(ans)

Submission status: Runtime Error

Solution code:
import collections
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
  print(0)
else:
  del d[0]
  c = collections.Counter(d)
  ll = len(c)
  ans = 1
  fl = False
  for i in range(1, ll+1):
    if c[i] == 0:
      print(0)
      fl = True
      break
    else:
      if i != 1:
        ans *= c[i-1]**c[i]

if not fl:
  print(ans%998244353)

Submission status: Runtime Error

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

d={}
for i in D:
    d[i]=d.get(i,0)+1

s = 0
for l in range(1, max(D)):
    if l == 1: s = 1
    for i in range(d[l+1]):
        s *= d[l]

print(s)

Submission status: Runtime Error

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

ans = 1
#n1が0ではない、もしくは他に0がある
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    ans *= D.count(i) ** D.count(i + 1)
    if ans == 0:
      break
print(ans / 998244353)

Submission status: Runtime Error

Solution code:
import sys
import collections
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
mD = max(D)

c = collections.Counter(D)
c = dict(c)

ans = 1
tmp = 1
for i in range(mD+1):
    if not(i in c.keys()):
        ans = 0
        break
    elif i == 0:
        if c[0] > 1:
            ans = 0
            break
    elif i == 1:
        tmp = c[i]
    else:
        ans = (ans * tmp**c[i])%MOD
        tmp = c[i]

if N == 1:
    if D[0] == 0:
        print(1)
    else:
        print(0)
elif N < 5:
    print(D[100])
else:
    print(ans)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
import math

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

ans = 0
flag = 0

dx = collections.Counter(d)


if(dx[0] != 1):
    flag = 1

ds = list(set(d))
if(len(ds) != ds[-1]+1):
    flag = 1
        
if(flag == 0):
    
    ans += 1
    for i in range(len(d)-1):
        ans *= math.pow(dx[i],dx[i+1])

print(round(ans))

Submission status: Runtime Error

Solution code:
mod = 998244353
n = int(input())
A = [int(x) for x in input().split()]

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    else:
        ans = 1
        for i in range(1,n):
            if L[i]>0:
                ans *= pow(L[i-1],L[i],mod)
                ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)

Submission status: Runtime Error

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

ans=1

if D[0]!=0:
  print(0)
else:
  for i in range(1,N):
    if D[i]!=0
    ans*=D[i]
  print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ls = list(map(int, input().split(' ')))
ans = 1
m = max(set(ls))
d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
if ans != 0:
    for i in range(1, m+1):
        if d.get(i, 0) == 0:
            ans = 0
            break
        ans = (ans * (d[i-1] ** d[i])) % 998244353
print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    for i in range(1, len(v)):
        print(ans)
        ans *= v[i-1]**v[i]
    print(ans % MOD)