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:
n = int(input())
d = list(map(int , input().split()))
max_d = 0
cnt = [0] * 10**5
for i in d:
    cnt[i] += 1
    max_d = max(i, max_d)
if cnt[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, max_d + 1):
        if cnt[i] == 0:
            ans = 0
            break
        ans *= cnt[i-1] ** cnt[i]
print(ans % 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 or l[0][1] != 1:
    answer = 0
else:
    for i in range(1, M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

    count = c[0]
    ans = 0
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i], MOD)

    print(count)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
c=[0 for i in range(max(d)+1)]
for x in d:
  c[x]+=1
if d[0]!=0 or (0 in c):
  print(0)
  exit()
for i in range(1,len(c)):
  ans*=c[i-1]**c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    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


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

a = collections.Counter(num_list)
maxim = sorted(num_list)[-1]

flag = 0
ans = 1
for i in range(1,maxim+1):
    if a[i-1] == 0:
        flag = 1
        break
    if a[i-1] != 1 and a[i] == 1:
        ans = ans * (a[i-1])
    
    elif a[i-1] != 1 and a[i] > a[i-1]:
        ans = ans * a[i-1] * (a[i-1] + (a[i]-1))
    elif a[i-1] != 1 and a[i] <= a[i-1]:
        ans = ans * a[i-1] * (a[i-1] + cmb(a[i-1], a[i]))
    
    elif a[i-1] == 1:
        ans = ans
    else:
        ans = ans * (a[i])
if flag == 1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

mem = [1 for i in range(n+1)]
for y in range(n):
  mem[y] = d.count(y)

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

Submission status: Wrong Answer

Solution code:
import collections

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

const = 998244353

c = collections.Counter(d)

m = max(d)

if c[0] != 1:
    print(0)
else:
    ans = c[0]
    for i in range(m):
        j = i + 1
        old = c[j - 1]
        new = c[j]
        if i == m - 1 and new == 0:
            ans = 0
            break
        else:
            ans = ans * (pow(old, new) % const) % const

    print(ans)

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    datas, counts = [_ for _ in range(max(A) + 1)], [0] * (len(A) + 1)
    for i in range(max(A) + 1):  # i = 0 ~ max(A)
        if i not in A:
            print(0)
            exit()
        else:
            counts[i] = A.count(i)
    return datas, counts


N = int(input())
D = list(map(int, input().split()))
D_datas, D_counts = ContinueCnt(D)
# print(D_datas, D_counts)  # for debug
INF = 998244353

# first check zero
if D_counts[0] != 1:
    print(0)
    exit()

ans = 1
# check 1 ~ max(D)
for i in range(1, max(D_datas) + 1):
    ans *= D_counts[i - 1] ** D_counts[i]
    ans %= INF
    # print("now = ", ans)  # for debug

print(ans % INF)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
deep,a,b,c = 0,1,0,1
for i in range(n):
  if s[i] == deep:
    b += 1
  elif i == n:
    c *= a ** b
  elif s[i] == deep + 1:
    c *= a ** b
    a = b
    b = 1
    deep += 1
  else:
    c = 0
    break
    
  if i == n-1:
    if s[i] == deep:
      c *= a ** b
    elif s[i] == deep + 1:
      c *= a ** b
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def solve():
    _ = int(input())
    a = [int(x) for x in input().split()]
    
    ct = Counter(a)
    total = 1
    v = 1
    n = max(a) + 1
    for i in range(n):
        if i not in ct:
            return 0
        
        if ct[i] > v:
            return 0
        
        # total *= ct[i]
        total = i*v
        # print(f'i: {i}, v:{v}')
        v *= 2

    return total%998244353

print(solve())

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(1, M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import tee

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


def pairwise(iterable):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


if D[0] > 0:
    print(0)
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e, R)
    print(ans)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d.count(0) != 1:
        print(0)
    else:
        count = 1
        prev = d[1]
        c = 1
        for i in d[2:]:
            if prev == i:
                c += 1
                continue
            elif prev + 1 == i:
                count = ((count % mod) * (prev**c % mod)) % mod
                c = 1
                prev = i
            else:
                count = 0
                break
        count = ((count % mod) * (prev**c % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
 
import numpy as np
 
if D[0]!=0:
  print(0)
else:
  for i in range(D.count(0)):
    D.remove(0)
  print(int(np.prod(D)))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if len(set(D))==1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(0,max(D)+1):
        #print(cnt[i],tmp)
        c = (tmp**cnt[i]) % mod
        ans *= c
        tmp = cnt[i]
        ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
 
import numpy as np
 
if D[0]!=0:
  print(0)
else:
  for i in range(D.count(0)):
    D.remove(0)
  D=[]
  print(int(np.prod(D)))

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
e = collections.Counter(d)
e = e.most_common()
e =list(e)
e.sort()

if d.count(0)!=1:
    print(0)
    exit()


for i in range(1,len(e)):
    if e[i][0]-e[i-1][0]!=1:
        print(0)
        exit()
    
    else:
        ans*=(e[i-1][1])**e[i][1]
        ans=ans%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
#b
n=int(input())
d=[int(i) for i  in input().split()]

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or len(set(d))!=max(d)+1 or 0 in d[1:]:
    print(0)
else:
    for i in range(1,len(c)):
        ans *= i**c[i] %m
    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:
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
    Count=[0]*(max(Ds)+1)
    Count[0]=1
    for i in range(1, max(Ds)+1):
        Count[i]=Ds.count(i)
        Ans[i]=(Ans[i-1]*(Count[i-1]**Count[i]))%998244353

    print(Ans[max(Ds)])

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

if res[0]>1:
    print(0)
    exit()

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-1)//2:
        cnt+=cmb(tmp,j)*2
        j+=1
    if tmp%2==0:
        cnt+=cmb(tmp,tmp//2)
    cnt+=pre
    ans=(ans%mod)*(cnt%mod)
    cnt=0
    pre=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]==1:
    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)
  else:
    print(0)
except KeyError:
  print(0)

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 = (ans % mod) * cnter[i-1][1] ** cnter[i][1]
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

print(ans)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (N):
  if D.count(i+1) == 0:
    print(0)
    exit()
  count = D.count(i+1)
  ans = ( ans * (prev**count) %998244353 ) 
  prev = count
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

Solution code:

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx < 2:
        if tree == 0:
            count = 0
    else:
        count *= tree_list[idx - 1]**tree
print(count)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
d=list(map(int,input().split()))
ans=1
d.sort()
acount=1
count=1

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
if d[-1]!=d[-2]:
  ans*=count
  
if d[0]==0:
  print(ans)
elif d[0]!=0:
  print(0)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

L = sorted(set(D))
d = {}
c = 0
F = (D[0] == 0)
if F:
    for i in L:
        if c != i:
            if (c + 1) == i:
                c += 1
            else:
                F = False
                break
if F:
    for i in D:
        d[i] = d.get(i, 0) + 1

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

print(s)

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 or d.get(0) >= 2) 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)

Submission status: Wrong Answer

Solution code:
import numpy as np

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 *= np.power(Back, Re) % 998244353
    result %= 998244353

    count += 1

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

    if k < count:
        break

print(result)

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 or l[0][1] != 1:
    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:
import sys
import bisect

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

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

D.sort()


ans = 1
cnt = []
for d in range(N):

    cnt.append(bisect.bisect(D, d))

for d in D:
    if d == 0 or d == 1:
        continue

    ans = ans * (cnt[d - 1] - cnt[d - 2]) % 998244353


print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

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

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

result = 1
for i in range(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:
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 % mod) * (prev ** now % mod) % mod
            prev = now+0
            now = 1
            distance += 1
        else:
            ans = 0
            break
    else:
        ans = (ans % mod) * (prev ** now % mod) % mod
    
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = Counter(list(map(int, input().split())))
if Dlist[0] == 1:
    num = 1
    mae = 1
    for key, value in sorted(Dlist.items()):
        num *= (mae ** value)
        mae = value % 998244353
    print(num % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
import bisect
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))


def pow_r(x, n):

    if n == 0:  # exit case
        return 1
    if n % 2 == 0:  # standard case ① n is even
        return pow_r(x ** 2, n // 2)
    else:  # standard case ② n is odd
        return x * pow_r(x ** 2, (n - 1) // 2)

li.sort()

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

li = li[bisect.bisect(li,1):]
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))

point = 1
for i in range(len(lin)):
    point*=pow(lin[i][0],lin[i][1])

print(point%998244353)

Submission status: Wrong Answer

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

mod=998244353
c=collections.Counter(D)

if D[0]!=0 or c[0]!=0:
  print(0)
else:
  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
  if node==n:
    print(ans%mod)
  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int,input().split()))
if not D[0] == 0:
    print("0")
if min(D[1:]) == 0:
    print("0")
else:
    ans = [pow(i,D.count(i)) for i in range(1,max(D)+1)]
    ans = np.prod(ans, axis = 0)
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
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:
N = int(input())
D = [int(d_) for d_ in input().split()]
 
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
    for d1, d2 in zip(D_count[:-1], D_count[1:]):
        ans *= d1**d2
    print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
 
import numpy as np
 
if D[0]!=0:
  print(0)
elif D.count(0)!=1:
  print(0)
else:
  print(np.prod(D))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, = map(int, sys.stdin.readline().rstrip().split(" "))
Ds = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Ds.sort()

if Ds.pop(0) != 0:
    print(0)
else:
    leaf_count = collections.defaultdict(int)
    leaf_count[0] = 1
    result = 1
    for D in Ds:
        if leaf_count[D - 1] == 0:
            result = 0
            break
        else:
            result *= leaf_count[D - 1]
            # result %= 998244353
            leaf_count[D] += 1
    print(result)
exit(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
D.sort()
result = 1
for i in range(max(D)):
    result *= D.count(i) ** D.count(i+1)
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import collections


n = int(input())

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


count_dict = collections.Counter(d)
result = 1
for i in range(1,max(d)+1):
    prenum = count_dict[i-1]
    nownum = count_dict[i]
    result *= prenum**nownum

result %= 998244353
 
print(result)

Submission status: Wrong Answer

Solution code:
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 = 1
while j in dic:
    if j-1 in dic:
        count *= dic[j-1]**dic[j]%998244353
        count %= 998244353
        j += 1
    else:
        print(0)
        exit()
print(count)

Submission status: Wrong Answer

Solution code:
divider = 998244353

num = int(input())
depths = [int(x) for x in input().split()]
max_depth = max(depths)

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

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

nodes = [0] * (max_depth+1)

for depth in depths:
  nodes[depth] += 1

if nodes[0] != 1 or min(nodes) == 0:
  print(0)
  exit(0)

arr = [(nodes[i] - 1) + nodes[i+1] for i in range(0, max_depth)]

ans = 1
for a in arr:
  ans = (ans * a)  % divider

print(ans)
exit(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
a=sorted([int(i) for i in input().split()])
#n=10**6
#a=[0]+[(i+2)//2 if i%2==0 else i//2+1 for i in range(n-1)]
c=Counter(a)
ans=1
if c[0]!=1:
    print(0)
    quit()

for i in range(n-1):
    if a[i+1]-a[i]>1:
        print(0)
        quit()

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


print(ans%998244353)

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()
for i in range(1,max(d)+1):
  ans *= d.count(i-1)**d.count(i)
print(ans%998244353)

Submission status: Wrong Answer

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

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

cnt = collections.Counter(D)
rng = range(0, max(cnt.keys()) + 1)

ans = 1
for i in rng:
    if i == len(rng) - 1:
        break
    n = cnt[i]
    r = cnt[i + 1]
    if n == 0 or r == 0:
        ans = 0
        break
    ans *= n ** r

print(int(ans))

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%998244353)

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):
            if int(k) != 0:
                ans *= int(k) ** len(list(g))
        print(ans % 998244353)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
d=sorted(d)
for j in range(0,n-1):
    if d[j+1]-d[j]>1:
        ans=0
        
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:
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    d = [int(e) for e in lines[1].split(" ")]

    return (n, d)


def solve(n, d):

    if d[0] != 0:
        return 0 
     
    d.sort()

    z = [] 
    tmp = d[0]
    count = 0
    for i in range(n):
        if tmp != d[i]:
            z.append((tmp, count))
            tmp = d[i]
            count = 1
        else:
            count = count + 1
    z.append((tmp, count))

    if z[0][0] != 0 or z[0][1] > 1:
        return 0

    result = 1
    m = len(z)
    for i in range(1, m):
        if z[i-1][0] + 1 != z[i][0]:
            result = 0
            break
        else:
            result = result * z[i-1][1] ** z[i][1]

    return result


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0 or i == 1:
        continue
    else:
        ct *= branch**b[i]
        branch = b[i]
if b[0] != 1:
    print(0)
else:
    print(ct)

Submission status: Wrong Answer

Solution code:
import collections

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

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

cntsum = 1
judge_cnt = 0

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

m = max(e)
e2 = dict(sorted(e.items()))
# print(e2)
beforekey = 1
for i in e2.keys():
    if i != 0:
        cntsum = cntsum * e2[beforekey] ** e2[i]

    if i - beforekey > 1:
        print(0)
        exit()
    beforekey = i

print(cntsum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

N = int(input())
D_list = list(map(int, input().split()))
P = 998244353
n = 1
c = Counter(D_list)
if c[0] != 1:
    print(0)
else:
    pre = 1
    for i in range(1, max(D_list) + 1):
        if c[i] == 0:
            print(0)
            sys.exit()
        n = (n * ((pre ** c[i]) % P)) % P
        pre = c[i]
    print(n)

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)
    if d.count(1) == len(d):
        print(len(d)-1)
    else:
        for j in range(len(d)):
            ans *= d[j]
        print(ans%998244353)

Submission status: Wrong Answer

Solution code:
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 = 1
while j in dic:
    if j-1 in dic:
        count *= dic[j-1]**dic[j]%998244353
        j += 1
    else:
        print(0)
        exit()
print(count)

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
    pre_v = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            pre_v = v
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        

        if v == pre_v - 1:
            ans *= (smaller**bigger)
            ans = ans % MOD
            pre_v = v
        else:
            ans = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
for i in range(1,N):
  if D.count(i)==0:
    break
  ans = ans*pow(D.count(i-1),D.count(i))
print(int(ans%998244353))

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
db = [0] * n
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

#末尾に連続する0を削除
if (db[n-1] == 0):
    l = n-1
    for i in range(1,n):
        tmp = db[n-i]
        if (tmp == 0) : l = n-i 
        else : break
    
    del db[l:n]


if (db[0] == 0):
    print(0)
    exit()
if (len(db) <= 2):
    print(len(db)-1)
    exit()

db.append(1)
ans = 1

for i in range(len(db)-1):
    tmp = (db[i]**db[i+1]) % MOD
    ans *= tmp

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))

print(D[1:].prod())