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

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    SSSS = 998244353
    D = string_to_int(inputs[0])
    # {distance: numbers}
    nodes = {}
    for i, d in enumerate(D):
        i += 1
        if d not in nodes:
            nodes[d] = [i]
        else:
            nodes[d].append(i)

    if 0 not in nodes:
        return 0

    prev = -1
    prev_num = -1
    count = 0
    for d in sorted(nodes.keys()):
        if d == 0:
            if not (len(nodes[d]) == 1 and nodes[d][0] == 1):
                return 0
            count = 1
            prev_num = 1
            continue
        if abs(d - prev) == 1:
            return 0

        count *= prev_num ** len(nodes[d])
        prev_num = len(nodes[d])
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
n,*D=map(int,open(0).read().split());a=1;M=[0]*-~max(D)
for d in D:M[d]+=1
for m,n in zip(M,M[1:]):a*=m**n
print((M[0]<2)*a%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 1
count1 = 1
count = 0
now = 0
mod = 998244353
if d[0] != 0:
    print(0)
else:
    for i in range(1,n):
        if d[i] == now+1:
            count += 1
        else:
            if count == 0 or d[i] == 0:
                ans = 0
                break
            elif d[i] > now + 2:
                ans = 0
                break
            else:
                p = 1
                for j in range(count):
                    p *= count1
                    p %= mod
                ans *= p
                ans %= mod
                count1 = count
                count = 1
                now += 1
        #print(count,count1,now)
    p = 1
    for i in range(count):
        p *= count1
        p %= mod
    ans *= p
    ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
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())
d = list(map(int,input().split()))
nc = [0]*(max(d)+1)
for i in range(0,n):
    nc[d[i]]+=1
if d[0]==0 and nc[0]==1 and nc.count(0)==0:
    ans = 1
    for i in range(1,len(nc)):
        ans *= nc[i-1]**nc[i]
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

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

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

#D.sort(reverse=True)


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

    elif d != 1:
        ans *= d

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d_list = [int(i) for i in input().split()]
R_max = max(d_list)+1
R = [0] * R_max
ans = 1

for di in d_list:
  R[di] += 1
  
if R[0] != 1:
  print(0)
  exit()
  
for i in range(1, R_max):
  ans *= R[i-1]**R[i]%998244353
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from itertools import dropwhile

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

dist = [0]*n

for i in D:
    dist[i] += 1

dist.reverse()
ddist = list(dropwhile(lambda x: x == 0, dist))
ddist.reverse()

ans = 1
for i in range(len(ddist) - 1):
    ans *= ddist[i] ** ddist[i+1]

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

Submission status: Wrong Answer

Solution code:
import collections
import sys

def read_a_integer():
    return int(sys.stdin.readline())

def read_a_list(dtype):
    return list(map(dtype, sys.stdin.readline().split()))

def main():
    N = read_a_integer()
    D = read_a_list(int)
    if D[0] != 0:
        print(0)
        return
    counter = collections.Counter(D)
    if counter[0] != 1:
        print(0)
        return
    max_D = max(D)
    ans = 1
    for i in range(2, max_D + 1):
        if i not in counter:
            print(0)
            return
        ans = (ans * counter[i-1] * counter[i]) % 998244353
    print(ans)

        


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
	print(0)
	exit()
if n==1:
	print(1)
	exit()
d.sort()
if d[1]==0:
	print(0)
	exit()
p=[]
cnt=1
if n==2:
	if d==[0,1]:
		print(1)
	else:
		print(0)
	exit()
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
	else:
		print(0)
		exit()
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=p[i]**p[i+1]
	ans%=mod
print(ans)

Submission status: Wrong Answer

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

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

def one_str():
    return input()

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

N=one_int()
D=many_int()

num=998244353

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

sums = 1
keys = sorted(list(dicts.keys()))
if len(keys)==1:
    sums=0

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

Submission status: Wrong Answer

Solution code:
from numpy import array, prod, nonzero
N = int(input())
Dlist = array(list(map(int, input().split())))
if Dlist[0] != 0:
    print(0)
else:
    print(prod(Dlist[nonzero(Dlist)]))

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
  print(0)
else:
  tmp=Counter(D)
  if tmp[0]!=1:
    print(0)
  else:
    ans=1
    for i in tmp.keys():
      if i==0 or i==1:
        continue
      ans*=tmp[i-1]**tmp[i]
    print(ans)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
import bisect

n = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
  print(0)
else:
  c = 1
  temp = 1
  D.sort()
  m = D[-1]
  for i in range(m+1):
    a = bisect.bisect_right(D, i)
    d = a - temp
    temp = a
    if d == 0 and i>0:
      print(0)
      exit()
    else:
      c *= i**d
      c %= 998244353
  print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
dis = 98244353
 
if D[0] != 0:
  print(0)
  exit()
D.sort()
if D[1] == 0:
  print(0)
  exit()
lis = list(set(D))[1:]
a = []
for i,n in enumerate(lis):
  num = D.count(n)
  a.append(num)
ans = 1
for i in range(1,len(a)):
  c = a[i-1]
  d = a[i]
  for _ in range(d):
    ans = ans*c
print(ans%dis)

Submission status: Wrong Answer

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

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

if d_list[0] != 0:
  print(0)
elif 0 in d_list[1:]:
  print(0)
else:
  d_count_dict = collections.Counter(d_list)
  start_num = -1
  start_cnt = 0
  answer = 1
  last = 1
  for num, cnt in d_count_dict.items():
    if num != start_num + 1:
      answer = 0
    else:
      answer *= last ** cnt
      last = cnt
      start_num = num
  print(answer)

Submission status: Wrong Answer

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

N = int(input().strip())
C = [0] * N
D = [int(x) for x in input().strip().split()]
maxD = max(D)
for d in D:
    C[d] += 1
ans = 1
c_ = 1
if D[0] != 0:
    ans = 0
else:
    for i, c in enumerate(C[1:], start=1):
        if i > maxD:
            break
        if c == 0:
            ans = 0
            break
        ans *= c_ ** c
        c_ = c

print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
n=int(input())
d=[int(i) for i in input().split()]
ans=[0]*n
for i in d:
    ans[i]+=1
f=mod
for i in ans:
    if f==0 and i>0:
        print(0)
        exit()
    f=min(f,i)
if d.count(0)!=1:
    print(0)
    exit()
cnt=1
if ans[2]==0:
    print(1)
    exit()
for i in range(1,n):
    if ans[i]==0:
        break
    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod

print(cnt%mod)

Submission status: Wrong Answer

Solution code:
INF = 998244353

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

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

if p[0]!=1:
    print(0)
    exit()
ans = 1
j = 1
for i in range(1,n+10):
    if p[i]==0:
        break

    ans = ans*(p[i-1]**p[i])
    ans = ans%INF
    j +=p[i]
if j!=n:
    print(0)
    exit()
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

d.sort()

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

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

ans = 1
num = 0
num_before = 1
now = 1
for i in d[1:]:
    if now == i:
        num += 1
    elif i > now+1:
        print(0)
        exit()
    else:
        ans = (ans * num_before**num) % 998244353
        num_before = num
        num = 1
        now = i

ans = (ans * num_before**num) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
MOD=998244353
d=list(map(int,input().split()))
max_d=max(d)
c=[0 for _ in range(max_d+1)]
for i in range(n):
    c[d[i]]+=1

ans=1
for i in range(max_d):
    ans*=c[i] ** c[i+1]
print(ans%MOD)

Submission status: Wrong Answer

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

x = [0] * (max(D)+1)
for i in range(N):

    x[D[i]] += 1

Sum = 1

for i in range(len(x)):

    if i != 0:
        Sum *= (x[i - 1] ** x[i])%998244353

    else:
        Sum *= x[i]

print(Sum)

Submission status: Wrong Answer

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline

mod=998244353

def main():
    n,*a=map(int,open(0).read().split())
    ans=1
    a=Counter(a)
    for i in range(len(a)-1):
        if a[i]==0 or a[i+1]==0:
            print(0)
            exit()
#        print(pow(a[i],a[i+1],mod),a[i],a[i+1])
        ans*=pow(a[i],a[i+1],mod)%mod
    print(ans%mod)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def count(x,D):
    res=0
    for i in range(len(D)):
        if D[i]==x:
            res+=1
        if D[i]>x:
            break
    return res
N=int(input())
D=list(map(int,input().split()))
D.sort()
m=max(D)
counter=[]
for i in range(m+1):
    counter.append(count(i,D))
ans=1
for i in range(1,m+1):
    ans*=counter[i-1]**counter[i]
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import sys


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

if d[0] != 0:
    print(0)
    sys.exit()
d.sort()
print(d)
ans = 1
key = 1
value = 1
for i in range(1, n):
    if i == 1 and d[i] != 1:
        print(0)
        sys.exit()
    else:
        pass
    if d[i] == d[i-1]:
        key += 1
    else:
        if d[i] == d[i-1] + 1:
            if d[i-1] == 1:
                value = key
                key = 1
            else:
                print(value, key)
                ans *= pow(value, key)
                print(ans)
                value = key
                key = 1
        else:
            print(0)
            sys.exit()
ans *= pow(value, key)
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):
    ans *= D[i]
if D[0] != 0:
    print(0)
else:
    print(ans%998244353)

Submission status: Wrong Answer

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





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

k=max(D)


ans=1
past=1
for i in range(1,k+1):
    n=D.count(i)
    if n==0:
        print(0)
        exit()
    ans*=past**n
    past=n

print(ans)

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
    else:
        if c[1] == 0:
            return 0
        else:
            res = 1
            for i in range(2, iter+1):
                if c[i] == 0:
                    return 0
                else:
                    res *= c[i-1]**c[i]%MOD
            return res
res = count(c, max(d))
print(res)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
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:]):
        print(l1, l2)
        ans *= pow(l1, l2, MOD)
        ans % MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

B = int(input())
Dlist = list(map(int, input().split()))

A = 998244353

D_max = max(Dlist)
cnt = [0] * (D_max + 1)

dic = Counter(Dlist)
for k, v in dic.items():
    cnt[k] = v

ans = cnt[0]

if ans != 1:
    print(0)

else:
    for i in range(D_max):
        ans = ans * ((cnt[i] ** cnt[i+1]) % A)
        ans = ans % A

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

n = int(input())
d_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(d_ls)
res = 1
if d_ls[0] != 0 or ct[0] > 1:
    print(0)
else:
    for i, count in sorted(ct.items(), key=lambda x:x[1]):
        if i == 0:
            continue
        res *= ct[i-1] ** count % 998244353
    print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
m=l1[-1]
if l1[0]!=0:
  print(0)
else:
  ld=[0 for i in range(m+1)]
  for i in range(n):
    ld[l[i]]+=1
  if ld[0]!=1:
    print(0)
  else:
    ans=1
    for i in range(1,m+1):
      if ld[i]==0:
        ans=0
      else:
        ans*=(ld[i-1]**ld[i])%(998244353)
    print(ans%(998244353))

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
d = [int(x) for x in input().split()]

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

ans = 1
for i in range(1, n):
    ans *= d[i]
if ans >= 998244353:
    ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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 == 1:
        tmp = c[i]
    else:
        ans = (ans * tmp**c[i])%MOD
        tmp = c[i]

print(ans)

Submission status: Wrong Answer

Solution code:
mod=998244353

N=int(input())
L=[0 for i in range(N)]
D=list(map(int,input().split()))
#print(D)
for i in range(N):
    L[D[i]]+=1
#print(L)

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

ans=1
cnt=1
for i in range(1,N):
    ans*=L[i-1]
    ans=pow(ans,L[i],mod)
    cnt+=L[i]
    #print(ans,cnt)
    if cnt==N:
        break
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = []
for i in range(max(D)+1):
    D_.append(D.count(i))
ans = 1
def m(i,j):
    return (i ** j) % 998244353

if N == 1:
    print(1)
else:
    for k in range(len(D_)-1):
        ans *= m(D_[k],D_[k+1])
        ans%998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]

for i in range(n):
  LL[L[i]] += 1
  
out = 1
for i in range(len(LL)-1):
  out *= pow(i+1, LL[i+1])

if L[0] != 0 or L.count(0) != 1:
  out = 0
print(out % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

N = int(input())
D = [int(_) for _ in input().split()]
if D[0] != 0:
    print(0)
    exit()

counter = Counter(D)
max(D)
cnt = 0
ans = 1
pre = 1
for i in range(1, max(D) + 1):
    if counter[i] == 0:
        print(0)
        exit()
    ans *= (pre ** counter[i]) % MOD
    ans = ans % MOD
    pre = counter[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
for i in range(1, len(A)):
    B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

ans = 1
for i in range(1, max_B):
    if A[0] != 0:
        ans = 0 
        break
        
    elif B[i] == 0:
        ans = 0 
        break
    else:
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353

n = int(input())
D = list(map(int,input().split()))
M = max(D)
L = [0]*(M+1)
for i in range(n):
    L[D[i]] += 1
if L[0]!=1:
    print(0)
else:
    ans = 1
    for i in range(1,M+1):
        ans *= L[i-1]**L[i]%MOD
    print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import collections


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

c = collections.Counter(D)
cm = c.most_common()

max_D = max(D)
ans = 1
previous_leaf = 1

if c[0] != 1:
    ans = 0
else:
    for i in range(1, max_D+1):
        ans *= (previous_leaf ** c[i])
        previous_leaf = c[i]

print(ans)

Submission status: Wrong Answer

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
  for i in range(1, ll+1):
    if c[i] == 0:
      print(0)
      break
    else:
      ans *= i**c[i]
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
import collections
N = int(input())
D = list(map(int, input().split()))
mx = max(D)
c = collections.Counter(D)

if c[0] == 1:
    ans = 1
    for i in range(1, mx+1):
        if i not in c:
            ans = 0
            break
        else:
            ans *= (c[i-1] ** c[i]) % MOD
            ans %= MOD
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
INFTY = 998244353
N = int(input())
D = list(map(int,input().split()))
C = {}
dmax = 0
for i in range(N):
    d = D[i]
    dmax = max(dmax,d)
    if d not in C:
        C[d] = 0
    C[d] += 1
flag = 0
for i in range(dmax+1):
    if i not in C:
        cnt = 0
        flag = 1
        break
    elif i==0 and C[0]>1:
        cnt = 0
        flag = 1
        break
if flag==1:
    cnt = 0
else:
    cnt = 1
    for i in range(1,dmax):
        cnt = (cnt*(C[i]**C[i+1]))%INFTY
print(cnt)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
A = list(map(int,input().split()))
D = [1 for _ in range(max(A)+1)]
for i in range(max(A)+1):
    D[i] = A.count(i)

ans = 1
if A[0] > 0:
    print(0)
else:
    for i in range(2,len(D)):
        ans *= (D[i-1]**D[i])%mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = [int(i) for i in input().split()]
a.sort()

c = collections.Counter(a)

ans = 1
now = 1
if a[0] != 0 or a[1]==0:
    print(0)
else:
    last = a[-1]
    for i in range(1,last+1):
        cnt = c[i]
        if cnt==0:
            ans = 0
            break
        else:
            ans *= now**cnt
            ans %= 998244353
            now = cnt
    print(ans)

Submission status: Wrong Answer

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 == 1:
        tmp = c[i]
    else:
        ans *= tmp**c[i]%MOD
        tmp = c[i]

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
D = {i:[] for i in range(max(d)+1)}
if sum(d) == 0:
  print(0)
  exit()
for i in range(n):
  if i == 0 and d[i] != 0:
    print(0)
    exit()
  if i != 0 and d[i] == 0:
    continue
  D[d[i]] += [i]
ans = 1

for i in range(max(d)):
  ans *= (len(D[i]) ** len(D[i+1])) % 998244353
  
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 998244353
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		if (a [ 0 ] != 0):
			print (0)
			continue
		a.sort()
		
		if(a[0]!=0):
			print(0)
		else:
			ox=[]
			cc=1
			las=a[0]
			for i in range(1,n):
				if(las==a[i]):
					cc+=1
				else:
					ox.append((las,cc))
					cc=1
					las=a[i]
			ox.append ((las, cc))
			if(ox[0][1]!=1):
				print(0)
			last=ox[0][1]
			next=ox[0][0]+1
			ans=1
			for i in range(1,len(ox)):
				if(next!=ox[i][0]):
					ans=0
				ans=(ans*pow(last,ox[i][1],mm))%mm
				last=ox[i][1]
				next+=1
			print(ans)










if __name__ == "__main__":
	solve ()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
d = list( map(int, input().split()))
c=Counter(d)
dmax = max(d)

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

ans = 1

for i in range(1,dmax):
    ans *= c[i]**c[i+1]
    if c[i] == 0:
        print(0)
        exit()

print(ans)

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
    else:
        if c[1] == 0:
            return 0
        else:
            res = 1
            for i in range(2, iter+1):
                if c[i] == 0:
                    return 0
                else:
                    res *= c[i-1]**c[i]
            return res

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

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time

setrecursionlimit(10**6)
input=stdin.readline

n=int(input())
d=[int(i) for i in input().split()]
m=max(d)
if d[0]!=0:
    print(0)
    exit()
dst=[0]*(m+1)
ans=1
for i in d: dst[i]+=1
print(*dst)
if dst[0]>1:
    print(0)
    exit()
for i in range(2,m+1):
    if dst[i]==0:
        print(0)
        exit()
    ans*=dst[i-1]**dst[i]
print(ans%998244353)

Submission status: Wrong Answer

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

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

def one_str():
    return input()

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

N=one_int()
D=many_int()

num=998244353

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

sums = 1
keys = sorted(list(dicts.keys()))
if len(keys)==1:
    sums=0

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

Submission status: Wrong Answer

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

D.sort()

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

chouten = {}
for i in D:
    if i not in chouten:
        chouten[i] = 0
    chouten[i] += 1

# print(chouten)

if 0 not in chouten or chouten[0] != 1:
    print(0)
    exit()

kosuu = 1
# for k, v in chouten.items():
#     if k == 0:
#         continue
#     if k == 1:
#     kosuu = kosuu**v

for i in range(len(chouten)):
    if i not in chouten:
        print(0)
        exit()
    if i == 0:
        continue
    elif i == 1:
        continue
        kosuu = chouten[i]
    else:
        kosuu *= chouten[i - 1]**chouten[i]
        kosuu = kosuu % 998244353

print(kosuu)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
d = [int(x) for x in input().split()]

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

ans = 1
for i in range(1, n):
    ans *= d[i]
    if ans >= 998244353:
        ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
mod = 998244353
if D[0]!= 0:
  print(0)
else:
  D.sort()
  if D[0]==0 and D[1]==0:
    print(0)
  else:
      D += [0]
      ans = 1
      before = 1
      now = 1
      for i in range(1,n):
          if D[i]==D[i+1]:
              now +=1
          else:
            ans *= ((before%mod)**now)%mod
            before = now
            now = 1
            ans = ans%mod
      print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
dc = collections.Counter(d).most_common()
dc = sorted(dc)
if d[0] == 0 and dc[0][1] == 1:
    count = 0
    ans = 1
    last = 1
    for i in dc:
        if i[0] == count:
            ans *= last ** i[1]
            last = i[1]
            count += 1
        else:
            print(0)
            exit()
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
def f():
    n = int(input())
    d = [int(s) for s in input().split()]
    d.sort()
    if d[0] != 0 or d[1] == 0:
        return 0
    maxD = d[-1]
    count = collections.defaultdict(int)
    for depth in d:
        count[depth] += 1
    ans = 1
    last = 1
    for i in range(maxD+1):
        if not last:
            return 0
        cur = count[i]
        ans *= (last**cur)
        last = cur
    return ans

print(f())

Submission status: Wrong Answer

Solution code:
import sys
N=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
  print(0)
  sys.exit()
if min(D[1:])==0:
  print(0)
  sys.exit()
D.sort()
ans=1
count1=1
count2=0
before=1
for i in D[1:]:
  if i==count1:
    count2+=1
  elif i==count1+1:
    ans = ans*(before**count2)
    count1+=1
    before=count2
    count2=1
  else:
    print(0)
    sys.exit()
  #print(ans,count1,count2,before)
print(ans*(before**count2))

Submission status: Wrong Answer

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()
ans = 1

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
D = list(map(int,input().split()))
D = sorted(D)
c = collections.Counter(D)
c = c.most_common()
c.sort(key=lambda x:x[0])
s = 1
key =0
for i in range(len(c)):
  if c[i][0] == 0:
    key += 1
  else:
    if i == 0:
      pass
    else:
      s *= c[i-1][1]**c[i][1]
if key == 1:
  print(s)
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()

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] and (d_list[i-1] != 1 or d_list[i-1] != 0):
        ans *= pre_strk ** now_strk
        pre_strk = now_strk
        now_strk = 1
        # print(ans)
    else:
        pre_strk = now_strk
        now_strk = 1
ans *= pre_strk ** now_strk
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


def main():
    n = int(input())
    d_s = list(map(int, input().split(' ')))

    if d_s[0] != 0:
        print(0)
        quit()

    dic = defaultdict(int)

    for d in d_s:
        dic[d] += 1

    t_s = sorted(dic.items())

    ans = 1

    pre_n = -1
    pre_count = 1


    for t in t_s:
        if t[0] - 1 != pre_n:
            print(0)
            quit()
        ans *= pre_count ** t[1]
        pre_n += 1
        pre_count = t[1]
    print(ans % 998244353)


if __name__ == '__main__':
    main()