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()))

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

ans=1

d.sort()

a=[0]*(n+1)

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

for j in range(n):
  if j!=0 and d[j] == 0:
    print(0)
    exit()
  else:
    ans*=(a[j]**a[j+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
else:
  m=max(a)
  b=[0]*m
  for i in a[1:]:
    b[i-1]+=1
  res=1
  #print(b)
  for i in range(1,len(b)):
    res*=b[i-1]**b[i]
  print(res%998244353)

998244353

Submission status: Wrong Answer

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

MOD = 998244353

def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


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

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

    x = 1

    for i in range(1, len(A)):
        x *= modPow(A[i-1], A[i], MOD)
        x %= MOD

    print(x)



if __name__ == '__main__':
    main()

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)
    exit()

ans = 1
idx = 1
C = sorted(Counter(D[1:]).items())
for k, v in C:
    if k != idx:
        print(0)
        exit()
    ans *= k ** v
    idx += 1
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

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

max_nums = max(nums)
cnt_list =collections.Counter(nums)
#print(cnt_list)

ans = 1
if cnt_list[0] == 1 and nums[0] == 0:
	for i in range(1, max_nums + 1):
		if cnt_list[i] == 0:
			print(0)
			break
		else:
			ans *= cnt_list[i - 1] ** cnt_list[i]
			#print(ans)
	print(ans)

else:
	print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353

N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
c = Counter(D)
if len(set(D)) != max(D) + 1:
    print(0)
    exit()
answer = 1
prev = 1
for k, v in c.items():
    answer *= prev ** v
    answer %= MOD
    prev = v
print(answer)

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)
    exit()
for i in range(1, n):
    if d[i] == 0:
        print(0)
        exit()

c = sorted(Counter(d).items())
ans = 1

for i in range(len(c)-1):
    if c[i][0] == 0: continue
    ans *= c[i][1] ** c[i+1][1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
mod=998244353
n=int(input())
d=list(map(int,input().split()))
z=[0]*n
for i in d:
    z[i]+=1
if z[0]!=1:
    print(0)
    exit()
ans=1
i=0
while n>0:
    if z[i]==0:
        print(0)
        exit()
    if i>0:
        ans*=pow(z[i-1],z[i],mod)
        ans%=mod
    n-=z[i]
    i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
tree = [(D[i], i) for i in range(N)]
tree.sort(key=lambda x: x[0])

if tree[0][0] > 0:
    print(0)
    exit()

ans = 1
mod = 998244353
b = 1

temp = 1
for i in range(1, N):
    if tree[i][0] != tree[i - 1][0]:
        b = temp
        temp = 1
    else:
        temp += 1
    ans *= b
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
D = Counter(D)
ans = 0
if D[0] != 1:
    print(ans)
else:
    for i, n in D.items():
        if i == 0:
            ans = 1
            continue
        ans *= pow(D[i-1], n, MOD)
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
ls.sort()
k=max(ls)
ls2=[0 for i in range(k+1)]
for e in ls:
  ls2[e]+=1
if ls2[0]!=1:
  print(0)
else:
  ans=1
  for i in range(1,k):
    ans*=(ls2[i]**ls2[i+1])
  print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=998244353
from collections import Counter
dd=Counter(d)
d.sort()
if len(d)==1:
  if d[0]:print(0)
  else:print(1)
  exit()
if not(d[0]==0 and d[1]!=0):print(0);exit()
a=1
for i in range(1,d[-1]+1):
  if dd[i]==0:a*=0
  else:a*=dd[i-1]**dd[i]
  a%=mod
print(a)

Submission status: Wrong Answer

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

MOD = 998244353

if D[0] == 0:

    D = D[1:]
    Max = max(D)
    l = []
    for ii in range(1, Max + 1):
        c = D.count(ii)
        if c == 0:
            l = []
            break
        else:
            l.append(c)

    if l != []:
        s = 1
        for ii in range(len(l) - 1):
            s *= l[ii] ** l[ii + 1]

        print (s)
    else:
        print (0)

else:
    print (0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#NIKEI B
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

tmp = input().split()
d = list(map(lambda a: int(a), tmp))

max=0
numlist={}
for i in range(0,n):
	if(d[i]>max):
		max=d[i]
	if(d[i] in numlist):
		numlist[d[i]]+=1
	else:
		numlist[d[i]]=1


if(d[0]!=0):
	print(0)
	sys.exit()
for i in range(max):
	if not(i in numlist):
		print(0)
		sys.exit()

ans=1
for i in range(1,max):
	#print(numlist[i])
	ans=ans*numlist[i]**numlist[i+1]

ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
aset = list(set(a))
a.sort()
aset.sort()

tmp = 0
for i in aset:
  if tmp == i:
    tmp += 1
  else:
    print(0)
    exit()

ans = 1
for i in range(1, N):
  ans = ans*a[i] %mod
print(ans)

Submission status: Wrong Answer

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

c=collections.Counter(d)
ans=1
ans=c[0]

if ans==1 and d[0]==0:
    for i in range(1,len(c)):
        ans*=(c[i-1]**c[i])%998244353
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

mod = 998244353

def main():
  n = ni()
  d = na()

  if d[0] == 1:
    print(0)
    return

  ans = 1
  for dd in d[1:]:
    ans *= dd
    ans %= mod
  print(ans % mod)
  

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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


def main():
    mod = 998244353
    N = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0 or D.count(0) != 1:
        print(0)
        return
    DD = dict()
    for d in D:
        if d in DD:
            DD[d] += 1
        else:
            DD[d] = 1
    li = sorted(DD.items(), key=lambda x:x[0])
    ans = 1
    x = 0
    pre_v = 1
#    print(li)
    for k, v in li:
        if k != x:
            print(0)
            return
        ans *= (pre_v**v) % mod
#        print(pre_v, x, k, v, ans)
        pre_v = v
        x += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
D=list(map(int,input().split()))
M=max(D)
l=[0]*(M+1)
for i in D:
    l[i]+=1
if l[0]==1:
    a=1
    for i in range(M):
        a*=pow(l[i],l[i+1],998244353)
    a%=998244353
    print(a)
else:
    print(0)

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)
    exit()

dic = Counter(D)

keys = sorted(dic.keys())
prev_num = 0
prev_count = 1
ans = 1
for num in keys:
    if num == 0:
        if dic[num] != 1:
            print(0)
            exit()
        continue

    if num - prev_num != 1:
        print(0)
        exit()

    count = dic[num]
    ans *= prev_count ** count
    prev_num = num
    prev_count = count

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, 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)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0 or 0 in d[1:]:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

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

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]
        tmp = c[i]
ans = ans * tmp

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
mod = 998244353
from collections import defaultdict
C = dict()
for i in range(max(D)+1):
    C[i] = 0
if D[0] > 0:
    print(0)
    exit()
for e in D:
    C[e] += 1
ans = 1
for key,item in C.items():
    if key == 0:
        continue
    if item == 0:
        print(0)
        exit()
    ans *= int(C[key-1]**item)
    ans = ans % mod
print(ans)

Submission status: Wrong Answer

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

MOD = 998244353

occ = [0 for i in range(N)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
for i in range(1, N):
    if occ[i] == 0:
        for j in range(i, N):
            if occ[j] != 0:
                print(0)
                quit()
        break
    if occ[i] != 0 and occ[i - 1] == 0:
        print(0)
        quit()
    for j in range(occ[i]):
        cur = (cur * occ[i - 1]) % MOD

print(cur % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
if D[0]!= 0:
  print(0)
else:
  D.sort()
  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**now
      before = now
      now = 1
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
MOD = 998244353

n = int(input())
D = list(map(int,input().split()))
D.sort()
M = max(D)
dic = defaultdict(int)

for i in range(n):
    dic[D[i]] += 1
ans = 1
if dic[0] == 1:
    for i in range(1,M+1):
        if dic[i] != 0:
            ans *= dic[i-1]**dic[i]%MOD
        else:
            print(0)
            exit()
    print(ans%MOD)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 1
cnt = [0] * (n)

if d[0] != 0:
  ans = 0
else:
  for i in d:
    cnt[i] += 1
  for i in range(2,n):
    ans *= cnt[i-1] ** cnt[i]

print(ans % 998244353)

Submission status: Wrong Answer

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

MOD = 998244353

def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


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

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

    x = 1

    for i in range(1, len(A)):
        x *= modPow(A[i-1], A[i], MOD)
        x %= MOD

    print(x)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
m = max(D)
c = collections.Counter(D)

if 0 not in c.keys() or c[0] != 1:
    print(0)
    exit()

temp = 1
for i in range(1, m+1):
    if i not in c.keys():
        print(0)
        exit()
    ans *= temp**c[i]
    temp = c[i]

print(ans % 998244353)

Submission status: Wrong Answer

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

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


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)}
for i in range(n):
  if i == 0 and d[i] != 0:
    print(0)
    exit()
  D[d[i]] += [i]
ans = 1
for i in range(max(d)):
  ans *= (len(D[i]) ** len(D[i+1])) % 998244353

print(ans)

Submission status: Wrong Answer

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

MAX_N = 10**5

fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
# Fmrmat's little theorem says a**(p-1) mod p == 1
# then, a * a**(p-2) mod p == 1
# it means that a**(p-2) is the inverse element
# Here, Get 1 / n! first
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

n = int(input())
d = [int(item) for item in input().split()]
max_val = max(d)
cnt = [0] * (max_val + 1)
for item in d:
    cnt[item] += 1

if 0 in cnt:
    print(0)
    exit()

ans = 1
for a, b in zip(cnt, cnt[1:]):
    ans *= pow(a, b, MOD)
    ans %= MOD
print(ans)

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)
    exit()

ans = 1
idx = 1
C = sorted(Counter(D[1:]).items())
for k, v in C:
    if k != idx:
        print(0)
        exit()
    ans = ans * (k ** v) % 998244353
    idx += 1
print(ans)

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

try:
    for i in range(max_D+1):
        ans *= (previous_leaf ** c[i])
        previous_leaf = c[i]
except:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
mod = 998244353
from collections import defaultdict
C = dict()
for i in range(max(D)+1):
    C[i] = 0
if D[0] > 0:
    print(0)
    exit()
for e in D:
    C[e] += 1
ans = 1
for key,item in C.items():
    if key == 0:
        continue
    if item == 0:
        print(0)
        exit()
    ans *= int(C[key-1]**item)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res



def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = list(set(a))
    d = Counter(a)
    if a[0] != 0:
        print(0)
    elif a[0] > 0:
        print(0)
    else:
        ans = 1
        for i in range(2, len(s) + 1):
            if d[i - 1] == 0:
                print(0)
                exit()
            ans = (ans * modpow(d[i - 1], d[i], 998244353)) % 998244353
        print(ans)
            

    
    

        
        
        
            

    
   


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=sorted(list(map(int,input().split())))
if d[0]!=0:
    print(0)
else:
    c=Counter(d)
    c_v=list(c.values())
    ans=1
    for i in range(1,len(c_v)):
        ans*=c_v[i-1]**c_v[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
M = 998244353
N = int(input())
D = list(map(int, input().split()))
ans = 1
if D[0] != 0:
    print(0)
else:
    flag = True
    ans = 1
    for di in D[1:]:
        if di == 0:
            flag = False
            break
        ans *= di % M
    if flag:
        print(ans)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
mod = 998244353
n = int(input())
dl = list(map(int,input().split()))

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

ans = 1
before_e = 1
now_e = 0
now = 0

for d in dl:
    if now != d:
        if now_e == 0:
            print(0)
            sys.exit()
        before_e = now_e
        now_e = 0
        now += 1
    now_e += 1
    ans *= before_e
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

d_max = Ds[-1]
for D in Ds:
    d[D] += 1

ans = 1
for i in range(1,d_max+1):
    ans *= d[i-1]**d[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
max_d = max(d)
ans = 1
cnt_prev = 1
for i in range(max_d+1):
  cnt = d.count(i)
  ans *= cnt_prev**cnt
  if ans==0:
    break
  cnt_prev = cnt
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
from collections import Counter
c = Counter([int(i) for i in input().split()])

if c[0] != 1:
  print(0)
  quit()


  
res = 1
for i in range(1,1+max(c.keys())):
  if i not in c.keys():
    print(0)
    quit()
  res *= c[i-1]**c[i]
  res %= 998244353
print(res)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 0
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_np = d_l[1:]
    ans = np.prod(d_np)
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
MOD = 998244353  # type: int

def solve(N: int, D: "List[int]"):
    if D[0] != 0:
        print(0)
        return 
    
    for i in range(1,N):
        if D[i]==0:
            print(0)
            return 

    D.sort()
    counter = Counter(D).items()

    answer = 1
    prev_node_count = 1
    for c in counter:
        answer*=prev_node_count**c[1]
        prev_node_count = c[1]
    
    print(answer%MOD)
    
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

c=collections.Counter(d)
ans=1
ans=c[0]

if ans==1:
    for i in range(1,len(c)):
        ans*=(c[i-1]**c[i])%998244353
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

if d[0] != 0:
    print(0)
else:
    for i in range(n):
        l.append(d.count(i))
        
    ans = 1
    for i in range(1, n):
        ans *= l[i-1] ** l[i]
    print(ans%wari)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
maxD = 0
count = [0 for _ in range(N)]
for d in D:
    maxD = max(maxD,d)
    count[d] += 1
answer = 1
for i in range(maxD):
    x = count[i]
    y = count[i+1]
    answer *= pow(x,y,MOD)
    answer %= MOD
if count[0] != 1:
    print(0)
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
X=[0]*10**5
for d in D[1:]:
  X[d-1]+=1
ans=1
i=1
while X[i]!=0:
  ans*=X[i-1]**X[i]
  i+=1
if X[1]==0:
  ans=0
print(ans%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:
                ans *= count1**(count)
                ans %= mod
                count1 = count
                count = 1
                now += 1
        #print(count,count1,now)
    ans *= count1**(count)
    ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

mv = max(a)

xs = [0] * (mv+1)
for y in a:
    xs[y] += 1

#print(xs)

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

print(ans)

Submission status: Wrong Answer

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

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

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

ans = ans * now**num
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
MOD = 998244353

n = int(input())
D = list(map(int,input().split()))
D.sort()
M = max(D)
dic = defaultdict(int)

for i in range(n):
    dic[D[i]] += 1
ans = 1
if dic[0] == 1:
    for i in range(1,M+1):
        if dic[i] != 0:
            ans *= dic[i-1]**dic[i]%MOD
        else:
            print(0)
            break
    print(ans%MOD)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	d = list(map(int,input().split()))
	z = defaultdict(int)
	for i in d:
		z[i] += 1
	mx = max(d)
	for i in range(mx+1):
		if i not in d:
			print('0')
			return
	ans = 1
	for i in reversed(range(1,mx+1)):
		ans *= z[i-1]**z[i]
	print(ans%998244353)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
    print(0)
    quit()
d.sort()

if d[1]==0:
    print(0)
    quit()
ans=1
last=1
now=1
cnt=0
i=1
while(i<n):
    if now==d[i]:
        cnt+=1
    elif now+1==d[i]:
        if cnt==0:
            print(0)
            quit()
        ans*=pow(last,cnt)
        last=cnt
        now=d[i]
        cnt=1
    else:
        print(0)
        quit()
    i+=1
if cnt>0:
    ans*=pow(last,cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
d = defaultdict(int)
m = 0
for i in a:
    d[i] += 1
    m = max(m,i)
res = 1
tmp = 1
for i in range(m+1):
    if i == 0:
        if d[i] != 1:
            print(0)
            quit()
        continue
    if d[i] == 0:
        res = 0
        break
    if i == 1:
        tmp = d[i]
        continue
    res *= tmp ** d[i]
    tmp = d[i]
print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 998244353

def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


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

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

    x = 1

    for i in range(1, len(A)):
        x *= modPow(A[i-1], A[i], MOD)%MOD

    print(x)



if __name__ == '__main__':
    main()

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:
    print(0)
    exit()

d.sort()

count = 1
count2 = 0
li = [1]

for i in range(1,n):
    if count == d[i]:
        count2 += 1
    else:
        li.append(count2)
        count += 1
        count2 = 1
li.append(count2)

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

print(ans)

Submission status: Wrong Answer

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

    if d.count(0) >= 2:
        print(0)
        exit()

    cnt = [0] * (max(d) + 1)

    for e in d:
        cnt[e] += 1

    ans = 1
    l = len(cnt)
    for i in range(l - 1):
        ans *= cnt[i] ** cnt[i+1] % mod

    ans %= mod
    print(ans)


if __name__ == "__main__":
    main()