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: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
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)
    check_ar = list(set(ar))
    for i in range(len(check_ar) - 1):
        if check_ar[i] + 1 != check_ar[i + 1]:
            ngflg = True
    if ngflg:
        print("0")
    else:
        ans_ar= []
        ans = 1
        for k, g in groupby(ar):
            ans_ar.append(len(list(g)))
        for i in range(1,len(ans_ar)):
            ans *= i ** ans_ar[i]
        print(ans)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
box = [0 for x in range(len(li))]
for i in li:
    box[i] += 1
count = 1
for i in range(2, len(box)):
    count *= box[i-1] ** box[i]

if box[0] != 1:
    count = 0

print(count % 998244353)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1
if l[0][0] != 0:
    answer = 0
else:
    for i in range(M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 1
if d[0] != 0:
    print(0)
else:
    zero_count = d.count(0)
    for i in range(zero_count):
        d.remove(0)
    for j in range(len(d)):
        ans *= d[j]
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
MOD = 998244353

n = int(input())
distances = list(map(lambda x: int(x), input().split()))

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in dist_list.keys():
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        if bigger == smaller + 1:
            ans *= (smaller**bigger)
            ans = ans % MOD
        else:
            ans = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = [int(_) for _ in input().split()]
c = Counter(d)
ans = 0

if d[0] == 0 and c[0] == 1:
    ans = 1
    if n > 1:
        for i in range(2,n+1):
            ans *= c[i-1]**c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

if D[0]!=0:
    print(0)
else:
    count_list = [ np.where(D==x,1,0).sum() for x in range(1,D.max()+1)]
    
    if 0 in set(count_list):
        print(0)
        sys.exit()
        
    ans = 1
    for x in range(len(count_list)-1):
        ans = (ans * (count_list[x]**count_list[x+1]))%998244353
        if ans == 0:
            print(0)
            sys.exit()
    print(ans)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans > 0:
    for i in range(1,maxkey): 
        ans=ans*dic[i]**dic[i+1]%MOD
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    for j in range(1, D.count(i + 1) + 1):
      ans *= D.count(i) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
def cnt_figure(ls):
    figure = 1
    figure_cnt = 0
    ls_len = len(ls)
    re_fg_ls = []
    for i in range(ls_len):
        if figure == ls[i]:
            figure_cnt+=1
        else:
            re_fg_ls.append(figure_cnt)
            if figure == ls[i]-1:
                figure+=1
                figure_cnt=1
            else:
                figure_cnt = 0
                break
    re_fg_ls.append(figure_cnt)
    return re_fg_ls

n = int(input())
d_list = list(map(int, input().split()))
#print(d_list)
total = 0
now_figure = 0
if d_list[0] != 0:
    print(0)
else:
    d_list.pop(0)
    d_list.sort()
    #print(d_list)
    figure_ls = cnt_figure(d_list)
    #print(figure_ls)
    figure_ls_len = len(figure_ls)
    before_cnt = 1
    total = 1
    for i in range(figure_ls_len):
         total = total *(before_cnt**figure_ls[i]) % 998244353
         #print(total,"total")
         before_cnt = figure_ls[i]
    print(total % 998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

def count_tree(n, d):
    if n < max(int(i) for i in d.keys()):
        return 0
    else:
        n = max(int(i) for i in d.keys())
    cnt = 1
    if d["0"] != 1:
        return 0
    for i in range(1, n):
        if d[str(i + 1)] > 0 and d[str(i)] < 1:
            return 0
        else:
            cnt *= d[str(i)] ** d[str(i + 1)]
    return cnt

print(count_tree(int(input()), Counter(input().split())))

Submission status: Wrong Answer

Solution code:
import math

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

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

D.sort()

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

ind_prev = 1

lst = [1]
num = 2

if max(D) == 1:
    print(max(len(D) - 1, 1))
    exit()

while True:
    try:
        ind = D.index(num)
    except:
        print(0)
        exit()
    
    lst.append(ind - ind_prev)
    ind_prev = ind

    if num == max(D):
        lst.append(len(D) - ind)
        break

    num += 1


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

print(ans)

Submission status: Wrong Answer

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: Wrong Answer

Solution code:
N = int(input())

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

E = sorted(D)

myans = 0

for i in E:
    if i == 0:
        myans = 1
    else:
        myans *= i
        
print(myans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
longest = max(D)
nums = [0]*(longest+1)
for i in range(longest+1):
    nums[i] = D.count(i)
ans = 1
for i in range(longest):
    ans = ans * (nums[i])**(nums[i+1]) % 998244353
print(ans)

Submission status: Wrong Answer

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

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

k = max(A)

count = 1
result = 1
Re = 1
while True:

    Back = Re
    Re = A.count(count)

    result *= Back ** Re % 998244353

    count += 1

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

    if k < count:
        break

print(result)

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0]*N
for D in Ds:
    counter[D] += 1
total = 0
cnt = 0
prenumi = 0
for i in range(N):
    if i == 0:
        if counter[i] == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = counter[i]
        if numi != 0:
            case = 1
            for j in range(numi):
                case = (case * prenumi) % CONST_DIVSOR
            total = (total % CONST_DIVSOR) * case
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break

print(total % CONST_DIVSOR)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


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


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    N = II()

    if N % 2 == 0:
        print((N//2)-1)
    else:
        print(N//2)
    return

# B


def B():
    N = II()
    D = LI()
    if D[0] != 0:
        print(0)
        return
    del D[0]
    if 0 in D:
        print(0)
        return
    ans = 1
    count = D.count(1)
    for i in range(1, N-1):
        x = D.count(i)
        y = D.count(i+1)
        if x == 0:
            print(0)
            return
        ans = ans*(x ** y)
        count += y
        if count == len(D):
            break
    print(ans)

    return

# C


def C():
    N = II()
    A = LI()
    B = LI()

    L = []
    count = 0
    for i in range(2, int(sqrt(N)+2)):
        if N % i == 0:
            L.append(N/i)
            count = 1
    if count == 0:
        print(N-1)
    else:
        print(int(L[-1]-2+(N/L[-1])))

    return

# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
dl=list(map(int,input().split()))
MOD=998244353
dist=[0]*n
for d in dl:
    dist[d]+=1
if dist[0]>1:
    print(0)
    exit()
ans=1
flg=False
for i in range(1,n):
    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: Wrong Answer

Solution code:
from sys import exit

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

c = {}
for i in D:
    if i in c:
        c[i] += 1
    else:
        c[i] = 1

d = list(c.keys())
d.sort()
if c[d[0]] != 1:
    print(0)
    exit()
if d[0] != 0:
    print(0)
    exit()

result = 1
for i in range(d[0] + 1, N + 1):
    if i not in c:
        if max(d) == i - 1:
            break
        else:
            print(0)
            exit()
    result = result * (c[i - 1] ** c[i]) % 998244353
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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


def pow_by_iter(a, x, n):
    acc = a
    for i in range(1, x):
        acc = (acc * a) % n
    return acc


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

d = Counter(D)
d_key = sorted(d.keys())
answer = 1

if len(d_key) > 1:
    for i in range(1, len(d_key)):
        if d_key[i] != d_key[i - 1] + 1:
            print(0)
            exit()
        else:
            answer *= pow_by_iter(d[d_key[i - 1]], d[d_key[i]], mod)
            answer %= mod

print(answer)

Submission status: Wrong Answer

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

mod=998244353
c=collections.Counter(D)

ans=c[0]
node=c[0]
for i in range(1,n):
  ans*=(c[i-1]**c[i])%mod
  node+=c[i]
  if node==n:
    break
print(ans%mod)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

n = int(input())
D = list(map(int, input().strip().split()))

if D[0] == 1:
    print(0)
    exit()
else:
    count = [0] * (len(D)+1)
    flag = [0] * (len(D)+1)
    for d in D:
        count[d] += 1
        flag[d] = 1

    ans = 1
    for i in range(1,sum(flag)):
        if count[i] <= 0:
            print(0)
            exit()
        else:
            ans *= i ** count[i]
    print(ans)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 1:
    for i in range(1,maxkey): 
        ans=ans*dic[i]**dic[i+1]%MOD
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=[0]*N
a=list(map(int, input().split()))
for i in range(N):
  D[a[i]]+=1
answer = 1
for i in range(N-1, -1, -1):
  if D[i]==0:
    a = D.pop(i)
  else:
    break
for i in range(len(D)-1):
  b =D[i]**D[i+1]
  answer *= b
  
print(answer)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1
if l[0][0] != 0:
    answer = 0
else:
    for i in range(M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer)

Submission status: Wrong Answer

Solution code:
# B - Counting of Trees
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

ans = 1
if D[0] > 0:
    print(0)
    exit()
else:
    for i in range(1,len(D)):
        if D[i] == 0:
            pass
        else:
            ans *= D[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

cntD = Counter(D)
ans = 1
for i in range(1, R + 1):
    ans *= pow(cntD[i - 1], cntD[i], MOD)
    ans %= MOD

if cntD[0] == 1 and all(cntD[i] >= 1 for i in range(R + 1)):
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for k in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for k in range(c)] for k in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N = INT()
A = LIST()

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

C = Counter(A)
depth = 0
ans = 1
prev = 1
for k, v in sorted(C.items()):
    if k != depth:
        print(0)
        exit()
    ans *= pow(prev, v, MOD)
    ans %= MOD
    depth += 1
    prev = v
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=10**9+7
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]!=1:
	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*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/11/9

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

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

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


def cmb(n,r,mod=10**9+7):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i%mod)
    ret=fac[n]*pow(fac[r]*fac[n-r]%mod,mod-2,mod)%mod
    return ret


ans=1
pre=res.get(1,-1)
if pre==-1:
    print(0)
    exit()

cnt=0
for i in range(2,len(res)):
    tmp=res.get(i,-1)
    if tmp==-1:
        print(0)
        exit()
    j=1
    while j<tmp:
        cnt+=cmb(tmp,j)
        j+=1
    cnt+=pre
    ans=(ans%mod)*(cnt%mod)
    cnt=0
    pre=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[]

for i in range(max(d)+1):
    count=d.count(i)
    num.append(count)
print(num)
ans=1
if d[0]!=0:
    print(0)
else:
    for i in range(1, max(d)+1):
        ans*=num[i-1]**num[i]
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())

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

if D[0] != 0 or D.count(0) !=1:
    print("0")
    exit()

m = max(D)
#counted = []

# for i in range(1,N):
#     counted.append(D.count(i))

#calc
result = 1
x = D.count(1)
for i in range(2,m+1):
    y = D.count(i)
    if y!= 0:
        result = result * pow(x,y)
        x = y
print(result)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

const = 998244353

m = max(d)

a = d.count(0)

if a == 0:
    print(0)
else:
    ans = a

    new = ans

    for i in range(m):
        j = i + 1
        old = new
        new = d.count(j)
        if new == 0:
            ans = 0
            break
        else:
            ans = (ans * pow(old, new)) % const

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def comb(y, x):
    if y // 2 < x:
        x = y - x
    t = 1
    for i in range(1, x + 1):
        t = t * (y + 1 - i) // i
    return t
mod = 998244353
def solve():
    n = int(input())
    D = Counter(map(int, input().split()))
    if 0 not in D:
        return 0
    max_d = max(D)
    if max_d == 1:
        return D[1]
    if max_d == 2:
        return D[1] * comb(D[1] + D[2] - 1, D[2] - 1)
    ans = D[1]
    for k in range(2, max(D) + 1):
        if k not in D:
            return 0
        v = D[k]
        last = D[k - 1]
        if last == 1:
            ans *= v
        elif v == 1:
            ans *= last
        else:
            ans += comb(last + v - 1, v - 1)
        ans %= mod
    return ans % mod
print(solve())

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
print(0)
c = Counter(D)
max_D = max(D)
if c[0]!=1:
  print(0)
  
elif max_D<=1:
  print(1)
  
else:
  answer=1
  for i in range(2,max_D+1):
    c_i2 = c[i]
    c_i1=c[i-1]
    answer *= c_i1**c_i2
    
  print(answer%998244353)

Submission status: Wrong Answer

Solution code:
def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    depth = max(d)
    counts = [d.count(i) for i in range(depth + 1)]
    pows = [mod_pow(a=counts[i - 1], n=counts[i], mod=MOD) for i in
            range(1, depth + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


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

Submission status: Wrong Answer

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

if D[0] != 0:
  print(0)
  exit()
  
maximum = max(D)
max_distance = [i+1 for i in range(maximum)]
count_list = [0 for i in range(maximum+1)]
for i in D:
  count_list[i] += 1
stock = 1
for i in max_distance:
  count_1 = count_list[i-1]
  count_2 = count_list[i]
  if count_1 == 0 or count_2 == 0:
    stock = 0
    break
  stock *= count_1**count_2

print(stock%998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections
def solve():
    sys.setrecursionlimit(100000)
    mod = 998244353

    N = int(input())
    D = list(map(int, input().split()))
    cnter = collections.Counter(D)
    cnter = sorted(cnter.items())

    ans = 1
    if cnter[0][0] != 0 or cnter[0][1] != 1 : 
        ans = 0
    elif cnter[1][0] != 1:
        ans = 0
    else:
        for i in range(2, len(cnter)):
            if cnter[i][0] != i:
                ans = 0
                break

            else:
                ans *= cnter[i-1][1] ** cnter[i][1]
    
    print(ans%mod)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
d = list( map(int, input().split()) )
MOD = 998244353

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0
    for i in range(2, iter+1):
        if c[i] == 0:
            return 0

    res = 1
    for i in range(2, iter+1):
        res *= c[i-1]**c[i]
        res %= MOD
    return res % MOD

res = count(c, max(d))
print(res)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
if D[0] != 0: print(0)
else:
    D = sorted(D)
    levels = [0 for _ in range(D[-1]+1)]
    for d in D:
        levels[d] += 1
    if 0 in levels or levels[0] > 1: print(0)
    else:
        ans = 1
        for l1, l2 in zip(levels, levels[1:]):
            ans *= pow(l1, l2, MOD)
            ans % MOD
        print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(map(int, input().split()))
s.sort()
item = 0
sum = 0
node = 0
count = 0
before = 0

for i in range(N):
    count = s.count(i)
    node += count
    if i == 0:
        if count != 1:
            break
        else:
            before = 1
            sum = 1
    else:
        if count == 0:
            break
        else:
            sum = sum * (before ** count)
            before = count

if node != len(s):
    print("0")
else:
    print(sum%998244353)

Submission status: Wrong Answer

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

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

count = 1
dmax = max(d)
num_array = [0] * (dmax+1)

for i in range(len(d)):
    num_array[d[i]] += 1

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

for i in range(1, dmax+1):
    count *= i ** num_array[i]
    count = count % 998244353
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = np.array([int(a) for a in input().split()])

num_at_dist = np.array([1] + [0] * (N-1) + [0]) # extra 0 at the end for index -1

if D[0] != 0:
    ans = 0
else:
    ans = 1
    D = np.sort(D)
    for i in range(1, N):
        dist = D[i]
        num_at_dist[dist] += 1
        ans *= num_at_dist[dist - 1]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from math import factorial
n = int(input())

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

D.sort()

num = 0
m = 0
mb = 1
S = 1
Sb = 1
for i in D:
    if i == num:
        m += 1
    elif i != num:
        a = factorial(m) * mb
        S *= a
        mb = m
        m = 1
        num += 1
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

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:
    for i 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**a)
ans=ans%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys

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

if D[0]!=0:
    print(0)
else:
    count_list = [ np.where(D==x,1,0).sum() for x in range(1,D.max()+1)]
    
    if 0 in count_list:
        print(0)
        sys.exit()
        
    ans = 1
    for x in range(len(count_list)-1):
        ans = (ans * (count_list[x]**count_list[x+1]))%998244353
        if ans == 0:
            print(0)
            sys.exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
def f():
    n = int(input())
    d = [int(s) for s in input().split()]
    d.sort()
    maxD = d[-1]
    if d[0] != 0:
        return 0
    if len(d)==1:
        return 1
    if d[1] != 1:
        return 0
    count = []
    v = 0
    c = 1
    for i in range(1,n):
        if d[i] == v:
            c += 1
        else:
            if d[i] != (v+1):
                return 0
            count.append(c)
            v += 1
            c = 1
    count.append(c)
    if len(count) != maxD+1:
        return 0

    ans = 1
    last = 1
    for cur in count:
        ans *= (last**cur)%998244353
        last = cur
    return ans % 998244353

print(f())

Submission status: Wrong Answer

Solution code:
def modpow(a, n, mod):
    bi = format(n, 'b')
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == '1':
            res = (res * a) % mod
    return res

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

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

ans = 1
for i in range(len(L)-1):
    ans *= modpow(L[i], L[i+1], mod)
    ans %= mod
    
if L[0] == 1:
    print(ans)    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

pre_strk = 1
now_strk = 1
ans = 1
n = int(input())
d_list = list(map(int,input().split()))
d_list.sort()
# print(d_list)
if d_list[0] != 0:
    print(0)
    sys.exit()
if d_list[1] == 0:
    print(0)
    sys.exit()

for i in range(1,n):
    if d_list[i] == d_list[i-1]:
        now_strk += 1

    elif d_list[i] > d_list[i-1] + 1:
        print(0)
        sys.exit()

    elif d_list[i] != d_list[i-1] and d_list[i-1] != 1:
        ans *= pre_strk ** now_strk
        pre_strk = now_strk
        now_strk = 1
        # print(ans)
        ans = ans % 998244353

    else:
        pre_strk = now_strk
        now_strk = 1
ans *= pre_strk ** now_strk
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
MOD = 998244353

n = int(input())
distances = list(map(lambda x: int(x), input().split()))

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in dist_list.keys():
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        ans *= (smaller**bigger)
        ans = ans % MOD
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    if d[0] != 0:
        print(0)
    
    else:
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        ans = 1
        j = 1
        for i,j in count.items():
            if i == 0:
                continue
            tmp = j
            ans *= i**j

        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


ans = 1
if min(d) != 0:
  ans = 0
d.sort()
num = 1
for i in range(1,len(d)):
  ans = ans * d[i]

print(ans%998244353)