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 collections
import numpy as np
import math

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

ans = 0
flag = 0

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

ds = list(set(d))
if(len(ds) != ds[-1]+1):
    flag = 1
        
if(flag == 0):
    dx = collections.Counter(d)
    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:
N=int(input())
ld=list(map(int,input().split()))
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
            #ans*=dd[i]**dd[i+1]
            ans*=mul
            ans%=DV
        print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

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

cnt = collections.Counter(A)

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

res = 1
for v in cnt.values():
  res *= v
print(res)

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] % 998244353
else:
    ans = 0

print(ans)

Submission status: Runtime Error

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]==0:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(1,n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]>=d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=p[i]**p[i+1]
	ans%=mod
print(ans,2/0)

Submission status: Runtime Error

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

if A[0] != 0:
  print(0)

cnt = collections.Counter(A)

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

res = 1
for v in cnt.values():
  res *= v
print(res)

Submission status: Runtime Error

Solution code:
N=int(input())
ld=list(map(int,input().split()))
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):
            ans*=dd[i]**dd[i+1]
            ans%=DV
        print(ans)

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]
else:
    ans = 0

print(ans % 998244353)

Submission status: Runtime Error

Solution code:

import sys
n = int(input())
array = list(map(int, input().split()))
dic = {}
for i in range(n):
    key = array[i]
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
j = 1
count = 0
if dic[0] == 1:
    count = 1
else:
    print(count)
    exit()

while j <= max(dic):
    if j in dic:
        count *= j**dic[j]

        j += 1
    else:
        print(0)
        exit()
print(count)

Submission status: Runtime Error

Solution code:
def q2(n, D):
    counts = [np.sum(D == level) for level in range(n)]
    if counts[0] == 0:
        return 0
    tmp = 1
    for i in range(2, n):
        if counts[i] == 0:
            return tmp
        tmp *= counts[i - 1] ** counts[i]
    return tmp


if __name__ == '__main__':
    MAXINT = 998244353

    # A 問題
    # n = int(input())
    # print(q1(n))

    # B 問題
    n = int(input())
    D = np.asarray(list(map(int, input().split(" "))))
    # n = 4
    # D = np.array([0, 1, 1, 2])
    # D = np.array([1, 1, 1, 1])
    # n = 7
    # D = np.array([0, 3, 2, 1, 2, 2, 1])
    print(q2(n, D) % MAXINT)

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]
else:
    ans = 0

print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

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

if D[0] > 0:
    print(0)
else:
    num = [0]*max(D)
    for i in range(1, N):
        if D[i] > 0:
            num[D[i]-1] += 1

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

print(ans % mod)

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
    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):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = [0]*(n-1)
for i in input().split():
  d[int(i)]+=1
if d[0]!=1:
  print(0)
else:
  mod = 998244353
  ans=1
  for i in range(n-2):
    ans*=(d[i]**d[i+1])%mod
  print(ans%mod)

Submission status: Runtime Error

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

ans = 1
# 距離:頂点に対応する辞書
if D[0] != 0:
    ans = 0
distance_dict = {0:1}
for i in D[1:]:
    if not i in distance_dict:
        distance_dict[i] = 1
    else:
        distance_dict[i] += 1

#dist_list = list((distance_dict.keys())) # 0~N-1 一つでもとんでったらアウト。距離がない
#print(distance_dict)

for i in range(1,max(distance_dict.keys())+1):
    if not i in distance_dict:
        ans = 0
    else:
        ans *= distance_dict[i-1]**distance_dict[i] # どこにつながるかの候補とつながる点の数
print(ans%BIGNUM)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    D = list(map(int, input().split()))
    count = Counter(D[1:])
    if D[0] != 0:
        # 頂点1に対しては、0以外有り得ない
        print(0)
        return
    results = [0, count[1]]
    for d in sorted(count.keys())[1:]:
        results.append(results[d - 1] * math.factorial(count[d]))
    print(sum(results[2:]) % 998244353)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = list(map(int, input().split()))

cnt = dict()
for k in d:
    if k in cnt:
        cnt[k] += 1
    else:
        cnt[k] = 1

mod = 998244353

keys = cnt.keys()
pre = -1
rst = 1

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

for k in sorted(keys):
    if (pre + 1) != k:
        rst = 0
        break
    pre = k

    if k == 0:
        continue

    rst = (rst * (cnt[k-1] ** cnt[k])) % mod
    
print(rst)

Submission status: Runtime Error

Solution code:
import sys

N = int(input())

lis = [0] * (10 ** 1 + 10)

D = list(map(int,input().split()))
maxi = 0

for i in D:
    maxi = max(maxi,i)
    lis[i] += 1

ans = 1
for i in range(maxi + 1):

    if i == 0 and lis[i] != 1:
        ans = 0
        print (0)
        sys.exit()
    elif i != 0:
        #print (ans,lis[i-1],lis[i])
        ans = ans * ( lis[i-1] ** lis[i] ) 
        ans %= 998244353

#print (lis)
print (ans % 998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
else:
    D = D[1:]
    C = [0]*N
    for d in D:
        C[d] += 1
    if C[0] != 0:
        print(0)
    else:
        res = 1
        for i in range(1, N - 1):
            res *= C[i]**C[i + 1]
    print(res)

Submission status: Runtime Error

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
if a[0]!=0:
    print(0)
    exit()

b = [0]*n
for i in a: b[i]+=1

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

ans = 1
i = 0
while 1:
    if b[i]==0:
        if sum(b[i:])>0:
            print(0)
            exit()
        else:
            break
    ans *= b[i]**b[i+1]
    i += 1

print(ans)

Submission status: Runtime Error

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

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

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            ans *= 0
    else:
        if a[i] > 0:
            if a[i-1] == 0:
                ans *= 0
                print(aa)
            else:
                ans *= pow(a[i-1], a[i], MOD)
                ans %= MOD
print(ans % MOD)

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    ans *= mapping[i]**(mapping[i+1])
  print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#define int long long
constexpr int MOD = 998244353;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
// constexpr int MOD = 100000000 + 7;

long long modpow(long long a, long long n)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);

    int n;
    cin >> n;
    vector<int> d(n);
    int d_max = 0;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        d[tmp]++;
        chmax(d_max, tmp);
    }

    int ans = 1;
    for (int i = 1; i <= d_max; i++)
    {
        ans = (ans * modpow(d[i - 1], d[i])) % MOD;
    }
    cout << ans << endl;
}

Submission status: Runtime Error

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
mx=d[-1]
count=[0]*(mx+1)
j=0
MOD=998244353
if d[0]!=0:
    print(0)
    sys.exit()
count[0]=1
j=1
for i in range(1,n):
    if d[i]==j:
        count[j]+=1
    elif d[i]==j+1 and count[i]>0:
        j+=1
        count[j]+=1
    else:
        print(0)
        sys.exit()
c=1
#print(d,count)
for i in range(1,mx+1):
    c*=pow(count[i-1],count[i],MOD)
    c%=MOD
print(c)

Submission status: Runtime Error

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


if D[0] != 0 or 0 in D[1:]:
    ans = 0
else:
    num = [0 for i in range(max(D)+1)]
    ans = 1
    cnt = 1
    for i in range(n):
        num[D[i]] += 1
    for i in range(len(num)):
        ans = ans * (cnt ** num[i]) % 998244353
        cnt = num[i]

print(num)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    ans *= mapping[i]**(mapping[i+1])
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
ds=[int(i) for i in input().split()]
ans=0
counts={}

if ds[0]!=0:
  ans=0
  
else:  
    for i in range(1,n):
      if ds[i] not in counts:
        counts[ds[i]]=1
      else:
        counts[ds[i]]+=1
    ans=1
    for i in range(1,len(counts)):
      x=(counts[i]**counts[i+1])%998244353
      ans*=x
      ans%998244353

print(ans%998244353)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
s = list(set(d))
s.sort()

cnt = []
for num in s:
  cnt += [d.count(num)]
#print(cnt)

ans = 1
for c in cnt:
  if c != 1:
    ans *= math.factorial(c)
    
ans *= cnt[1]
print(ans%MOD)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

D.sort()
mod = 998244353

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

Submission status: Runtime Error

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

x = [-1] * (N - 1)
for i in range(N):

    if x[D[i]] == -1:
        x[D[i]] = 0

    x[D[i]] += 1

Sum = 1

for i in range(N - 1):
    if x[i] == -1:
        break
    else:
        if i != 0:
            Sum *= (x[i - 1] ** x[i])%998244353

        else:
            Sum *= x[i]

print(Sum)

Submission status: Runtime Error

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

c = collections.Counter(d)
if d[0] != 0:
  print(0)
  sys.exit()
c = dict(collections.Counter(d))
max_key = max(c.keys())

count = 1
for i in range(1,max_key):
  a = c.get(i, -1)
  b = c.get(i+1, -1)
  if a == -1:
    print(0)
    sys.exit()
  count = count * (a**b)

print(count)

Submission status: Runtime Error

Solution code:
import math

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

dist = [0 for i in range(n)]
for i in range(n):
    dist[a[i]] += 1
#print(dist)
ans = 1

if (a[0]!=0):
    print(0)
else:
    
    now = 1
    total = 1
    while(total<n):
        for j in range(dist[now]):
            ans *= dist[now-1]
            ans %= 998244353
            total+=1
        now+=1
        
    print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics

# qsort(array[])
def qsort(seq):
  if len(seq) < 1:
      return seq
  pivot = seq[0]
  left = []
  right = []
  for x in range(1, len(seq)):
    if seq[x] <= pivot:
        left.append(seq[x])
    else:
        right.append(seq[x])
  left = qsort(left)
  right = qsort(right)
  foo = [pivot]
  return (left + foo + right)

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

ans = 1
if d[0] == 1:
  print('0')
else:
  ds = qsort(d)
  for i in range(1, n):
    ans *= ds[i]
    # print(ans)
  print(ans)

Submission status: Runtime Error

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

x = [-1] * (N - 1)
for i in range(N):

    if x[D[i]] == -1:
        x[D[i]] = 0

    x[D[i]] += 1

Sum = 1

for i in range(N - 1):
    if x[i] == -1:
        break
    else:
        if i != 0:
            Sum *= x[i - 1] ** x[i]
         
        else:
            Sum *= x[i]
            
print(Sum)

Submission status: Runtime Error

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

import collections
def counter_list(A):
  counter = collections.Counter(A)
  counter =  [list(e) for e in counter.items()]
  counter.sort() #sortしたい場合はつける
  return counter

if(D[0] != 0): ans = 0
else: 
  D = counter_list(D)
  ans = 1
  for i in range(len(D)-1):
    if(i>=1):
      a = D[i]%998244353
      b = D[i+1]
      ans = ans%998244353
      ans = ans*(a**b)
      ans = ans%998244353
print(ans)

Submission status: Runtime Error

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

ans = 1
count = {}
for i in range(N):
  if i < D[i] or (i > 0 and D[i] == 0):
    print(0)
    exit()
  else:
    if D[i] in count:
      count[D[i]] += 1
    else:
      count[D[i]] = 1
    if D[i] > 0:
      ans *= count[D[i]-1]
print(ans)

Submission status: Runtime Error

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

if c != 1:
    print(0)
else:
    count = 1
    for i in range(2, 10 ** 5):
        ix = d.index(i)
        if ix:
            idx = ix
            break

    for i in d[idx:]:
        count *= i % mod
    print(count)

Submission status: Runtime Error

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

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

if n == 1:
    if d[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

if n == 2:
    if d[1] == 1:
        print(1)
        exit()
    else:
        print(0)
        exit()


a = [0]*(n-1)

while d:
    s = d.pop()
    a[s] += 1

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

ans = 1

for i in range(n-2):
        ans *= a[i]**a[i+1]
        ans %= mod

print(ans % mod)

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int, input().split()))
li = sorted(li)
count = 1
if  not (1 in li and 0 in li) :
    count = 0
else:
    for i in range(2,max(li) + 1):
        a = li.count(i-1)
        b = li.count(i)
        count *= a ** b
print(count % 998244353)A

Submission status: Runtime Error

Solution code:
n=int(input())
ds=[int(i) for i in input().split()]
ans=0
counts={}
if ds[0]!=0:
  ans=0
  
else:  
    for i in range(1,n):
      if ds[i] not in counts:
        counts[ds[i]]=1
      else:
        counts[ds[i]]+=1
    ans=1
    for i in range(1,len(counts)):
      ans*=counts[i]**counts[i+1]

print(ans)

Submission status: Runtime Error

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

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

a = [0]*(n-1)

while d:
    s = d.pop()
    a[s] += 1

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

ans = 1

for i in range(n-2):
        ans *= a[i]**a[i+1]
        ans %= mod

print(ans % mod)

Submission status: Runtime Error

Solution code:

import sys

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

D.sort()
T = [0 for _ in range(N)]

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

i = 0
ans = 1
if T[i] != 1:
    print(0)
    sys.exit()
pre = T[i]
i += 1
while T[i] != 0:
    ans *= pow(pre,T[i],mod)
    ans %= mod
    pre = T[i]
    i += 1

while i < N:
    if T[i] > 0:
        print(0)
        sys.exit()
    i += 1

ans %= mod
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
d=[int(i) for i  in input().split()]
from operator import mul
from functools import reduce

def cmb(n,r,mod):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under % mod

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

Submission status: Runtime Error

Solution code:
from collections import Counter
input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

MOD = 998244353
N= int(input())
D = inpl()
C = Counter(D)

if (D[0] != 0) or (C[0] != 1):
    print(0)
else:
    M = max(C.keys())
    ans = 1
    for i in range(M):
        ans = ans * pow(C[i], C[i+1], MOD) % MOD
    print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
lists=list(map(int,input().split()))
anslist=[0 for i in range(n+1)]
for j in lists:
    anslist[j]+=1

ans=1
counter=1
if anslist[0]!=1:
    print(0)
else:
    for j in range(n):
        if anslist[j]!=0 and anslist[j+1]!=0:
            counter=anslist[j]
            for j in range(anslist[j+1]):
                ans*=counter
                ans%(998244353)
        elif anslist[j+1]==0 and anslist[j]!=0:
            break
	print(ans)

Submission status: Runtime Error

Solution code:
def inpl(): return list(map(int, input().split()))

MOD = 998244353
N= int(input())
D = inpl()
C = Counter(D)

if (D[0] != 0) or (C[0] != 1):
    print(0)
else:
    M = max(C.keys())
    ans = 1
    for i in range(M):
        ans = ans * pow(C[i], C[i+1], MOD) % MOD
    print(ans)

Submission status: Runtime Error

Solution code:
import sys

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

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

d.sort()

for i in range(n-1):
    if d[i]>d[i+1] or d[i]+1<d[i]:
        print(0)
        sys.exit()

m = max(d)

cnt = {i:0 for i in range(1,m+1)}

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

mod = 998244353
 
ans = 1

for i in range(2,m+1):
    ans *= pow(cnt[i-1],cnt[i],mod)
    ans %=mod 

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
p=1
for i in input().split():
    if int(i)>1:
        p*=str(i)
print(p%998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
p=1
for i in input().split():
    if int(i)>1:
        p*=i
print(p%998244353)