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

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n = int(input())
    d = list(map(int, input().split()))
    if d[0] != 0:
        print(0)
        return 0
    mod = 998244353
    m=max(d)
    d = Counter(d)
    ans=1
    for i in range(1, m+1):
        ans = (ans * pow(d[i - 1], d[i], mod)) % mod
    print(ans)
main()

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)
if 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:
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)

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
for i in range(max_D+1):
    ans *= (previous_leaf ** c[i])
    previous_leaf = c[i]

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 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 = list(map(int, input().split()))
M = [0]*N
for d in D: M[d]+=1

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

ans = 1
mod = 998244353
for i in range(1,N):
    if M[i]>0:
        ans *= (M[i-1]**M[i])
        ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
cnt = 1
if d[0] != 0:
    print(0)
else:
    for i in range(1, n):
        cnt *= d[i]
        cnt %= 998244353
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
n=int(input())
a=deque(sorted([int(i) for i in input().split()]))
ans=1

if not (a[0]==0 and a[1]!=0):
    print(0)
    quit()

a.popleft()
for i in a:
    ans *= i
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod =  998244353
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
class BigCombination(object):

    def __init__(self, mod: int=10**9+7, max_n: int=10**6):
        fac, inv=[1], []
        fac_append, inv_append=fac.append, inv.append

        for i in range(1, max_n+1):
            fac_append(fac[-1] * i % mod)

        inv_append(pow(fac[-1], mod-2, mod))

        for i in range(max_n, 0, -1):
            inv_append(inv[-1] * i % mod)

        self.mod, self.factorial, self.inverse=mod, fac, inv[::-1]

    def get_combination(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[r] * self.inverse[n-r] % self.mod

    def get_permutation(self, n, r):
        if n < r:
            return 0
        return self.factorial[n] * self.inverse[n-r] % self.mod
#mint
class ModInt:
    def __init__(self, x):
        self.x = x % mod
    
    def __str__(self):
        return str(self.x)
    
    __repr__ = __str__

    def __add__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x + other.x)
        else:
            return ModInt(self.x + other)

    __radd__ = __add__
        
    def __sub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x - other.x)
        else:
            return ModInt(self.x - other)

    def __rsub__(self, other):
        if isinstance(other, ModInt):
            return ModInt(other.x - self.x)
        else:
            return ModInt(other - self.x)

    def __mul__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * other.x)
        else:
            return ModInt(self.x * other)

    __rmul__ = __mul__

    def __truediv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, mod-2,mod))
        else:
            return ModInt(self.x * pow(other, mod - 2, mod))
            
    def __rtruediv(self, other):
        if isinstance(other, self):
            return ModInt(other * pow(self.x, mod - 2, mod))
        else:
            return ModInt(other.x * pow(self.x, mod - 2, mod))
            

    def __pow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(self.x, other.x, mod))
        else:
            return ModInt(pow(self.x, other, mod))
            

    def __rpow__(self, other):
        if isinstance(other, ModInt):
            return ModInt(pow(other.x, self.x, mod))
        else:
            return ModInt(pow(other, self.x, mod))
def main():
    N=I()
    D=LI()
    if D[0]!=0:
        print(0)
        exit()
    ans = ModInt(1)
    
    cnt = [0]*N
    for i,d in enumerate(D):
        cnt[d]+=1

    for i,c in enumerate(cnt[1:],start=1):
        if cnt[i-1]==0 and c!=0:
            print(0)
            exit()
        if c==0 and cnt[i-1]==0:
            continue

        ans *= pow(cnt[i-1],c)


    if cnt[0]<1:
        print(0)
        exit()
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:print(0)
else:
  a.sort()
  mod=998244353
  if n==1:print(1)
  elif a[1]==0:print(0)
  else:
    li=[]
    ans=1
    a+=[-1]
    check=0
    for i in range(1,n):
      if a[i]!=a[i+1]:
        if li==[]:
          li.append(i)
          check=i
        else:
          li.append(i-check)
          check=i
    for i in range(len(li)-1):
      ans=ans*(li[i]**li[i+1])
      ans%=mod
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
s=[0]*n
m=998244353
for i in d:
    s[i]+=1
if s[0]==1:
    c=1
    a=1
    for i in range(1,n):
        if s[i]>0:
            c+=s[i]
            a=(a*pow(s[i-1],s[i],m))%m
        else:
            break
    if c==n:
        print(a%m)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

for i in Dlist:
    cnt[i] += 1

ans = cnt[0]

if ans !=1:
    print(0)

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

    print(ans)

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 cmb(n, r):
    if n-r<0:
        return 0
    else:
        return factorial(n) // factorial(r) // factorial(n - r)

def main():
    n,*a=map(int,open(0).read().split())
    x=set(a)
    ans=1
    if x==set(range(len(x))):
        a=Counter(a)
        for i in range(len(x)-1):
            ans*=pow(a[i],a[i+1],mod)%mod
        print(ans%mod)
    else:
        print(0)
        
    
    
if __name__ == '__main__':
    main()

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
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)
                count1 = count
                count = 1
                now += 1
        #print(count,count1,now)
    ans *= count1**(count)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline

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

if d[0] > 0:
  print(0)
  exit(0)
e = dd(int)
e[0] = 1
for i in range(1, N):
  if d[i] == 0:
    print(0)
    exit(0)
  e[d[i]] += 1
res = 1
for k in range(1, max(e.keys()) + 1):
  res *= pow(e[k - 1], e[k], mod)
  #print(res)
print(res)

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()))
	d.sort()
	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,len(zip(d)))):
		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:
from collections import Counter
MOD = 998244353
N = int(input())
Ds = list(map(int, input().split()))

ct = Counter(Ds)
M = max(ct)
ans = 1
if ct[0] != 1:
    print(0)
    exit()
last = 1
for i in range(M+1):
    ans *= last ** ct[i]
    last = ct[i]
    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]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dict = defaultdict(int)

mod = 998244353
N = int(input())
D = [int(x) for x in input().split()]
dep = max(D)
for d in D:
    dict[d]+=1

if(dict[0]>1):
    ans = 0
else:
    ans = 1
for de in range(1,dep+1):
    ans *= dict[de-1]**dict[de]
    ans %= mod
print(ans%mod)

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()
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
    prev = v
print(answer)

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]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def power_func(a, n, p):
    bi = str(format(n, "b"))
    res = 1
    for i in range(len(bi)):
        res = (res*res) % p
        if bi[i] == "1":
            res = (res*a) % p
    return res


n = int(input())
d = Counter(sorted(map(int, input().split())))
prev_count = 1
prev_index = -1
MOD = 998244353
ans = 1
for k, v in d.items():
    if k != prev_index+1:
        print(0)
        exit(0)
    ans *= power_func(prev_count, v, MOD)
    ans %= MOD
    prev_index = k
    prev_count = v
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def solve():
    N = int(input())
    D = map(int, input().split())
    E = [[] for i in range(N)]
    for i,d in enumerate(D):
        E[d].append(i)

    if [0] != E[0]:
        return '0'
    res = 1
    e_ = E[0]
    for i,e in enumerate(E[1:], start=1):
        if e:
            res *= len(e_)**len(e)
            e_ = e
        else:
            if any(E[i+1:]):
                return '0'
            else:
                return str(res%998244353)

if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
cnt = 1
if d[0] != 0:
    print(0)
else:
    for i in range(1, n):
        cnt *= d[i]
    print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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]
        else:
            print(0)
            break
    print(ans)
else:
    print(0)

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 cmb(n, r):
    if n-r<0:
        return 0
    else:
        return factorial(n) // factorial(r) // factorial(n - r)

def main():
    n,*a=map(int,open(0).read().split())
    x=set(a)
    ans=1
    if x==set(range(len(x))):
        a=Counter(a)
        for i in range(len(x)-1):
            ans*=pow(a[i],a[i+1],mod)%mod
        print(ans)
    else:
        print(0)
        
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

from collections import Counter
def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n = ri()
    ld = rli()
    if ld[0] != 0:
        print(0)
        return
    counter = Counter()
    for d in ld:
        counter[d] += 1
    cnt = 0
    ans = 1
    bef = 1
    be = -1
    for e, c in sorted(counter.items()):
        if e-be > 1:
            print(0)
            return
        ans *= pow(bef, c)
        ans %= 998244353
        cnt += c
        # print(be, e, c, pow(bef, c))
        be = e
        bef = c
    print(ans)





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    d = sorted(list(map(int,input().split())))
    l = [0]*(d[-1]+1)
    for i in d:
        l[i] += 1
    ans = 0
    if not 0 in l and d[1] > 0:
        ans = 1
        for i in range(1,len(l)):
            ans = ans*(l[i-1]**l[i])%998244353
    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)
    print(a)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections

def main():
    N=int(input())
    DL=[int(x) for x in input().split()]
    DL.sort()
    if DL[0]!=0:
        return 0

    dic=collections.Counter(DL)
    if dic[0]!=1:
        return 0
    keys=dic.keys()
    result=1
    for i in range(1,max(keys)+1):
        if dic[i]==0 and dic[i-1]==0:
            return 0
        result*=dic[i-1]**dic[i]

    return result


print(main())

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]
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys
MOD = 998244353

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

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

T = [0] * N

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

for i in range(1, N):
    if T[i] > 0 and T[i-1] == 0:
        print(0)
        sys.exit(0)

ans = 1
for i in range(2, N):
    if T[i] == 0:
        break
    # ans = (ans * int(math.pow(T[i-1], T[i])) % MOD
    ans = (ans * (T[i-1] ** T[i])) % MOD

print(ans)

Submission status: Wrong Answer

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

n=int(input())
d=map(int,input().split())
c = collections.Counter(d)
ans = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
if D[0] != 0:
    print(0)
    exit()

X = defaultdict(int)

for d in D:
    X[d] += 1

M = max(D)
ans = 1
for i in range(1, M):
    if X[i] == 0:
        print(0)
        exit()
    else:
        ans *= pow(X[i], X[i+1], mod)
print(ans%mod)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
ds = [0] * N
max_D = 0

for d in map(int, input().split()):
    ds[d] += 1
    max_D = max(max_D, d)
if ds[0] != 1:
    print(0)
    quit()
if any(ds[i] == 0 for i in range(1, max_D + 1)):
    print(0)
    quit()

ans = 1
for d in range(1, max_D + 1):
    ans *= pow(ds[d-1], ds[d], mod)
    ans %= mod
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)
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:
import math

def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# 
# a, b
# s = input()


MOD = 998244353

def repeatSquares(x, n):  # x^n
    res = 1
    while n != 0:
        if n % 2 == 1:
            res *= x
            res %= MOD  # MOD演算ないなら消していい
        x *= x
        n //= 2
        x %= MOD      # MOD演算ないなら消していい
    return res

N = int(input())
D = [0] + list(map(int, input().split()))

ans = 0
if D[1] == 0:
    D = D[2:]
    D.sort()
    
    ans = 1
    
    now = 1
    preCnt = 1
    cnt = 0
    for e in D:
        if e == now:
            cnt += 1
        else:
            ans *= repeatSquares(preCnt, cnt)
            ans %= MOD

            preCnt = cnt
            cnt = 1
            now += 1
    ans *= repeatSquares(preCnt, cnt)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dict = defaultdict(int)

mod = 998244353
N = int(input())
D = [int(x) for x in input().split()]
dep = max(D)
for d in D:
    dict[d]+=1

if(dict[0]>1):
    ans = 0
else:
    ans = 1
for de in range(1,dep+1):
    ans *= dict[de-1]**dict[de]
print(ans)

Submission status: Wrong Answer

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

f=True
d={}
a=0
for i in range(N):
	if D[i] not in d:
		if D[i]==a:
			d[D[i]]=1
			a=D[i]+1
		else:
			f=False
			break
	else:
		d[D[i]] += 1

if not(f):
	print(0)
else:
	ans=1
	d = list(d.values())
	for i in range(1, len(d))[::-1]:
		ans *= (d[i-1]**d[i])
		ans %= 998244353
	print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
D = list(map(int, input().split()))

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

div = 998244353

c = Counter(D)

maxD = max(D)
res = 1
for i in range(1, maxD):
    res *= (c[i]**c[i+1])
    res %= div

print(res)

Submission status: Wrong Answer

Solution code:
import collections

MOD=998244353
N=int(input())
D=list(map(int, input().split()))
c=collections.Counter(D)
counter=sorted(c.items(), key=lambda x:x[0])
if D[0]!=0 or counter[0][1]>1:
  print(0)
else:
  ans=1
  for i in range(2, len(counter)):
    ans=(ans*(counter[i-1][1]**counter[i][1])%MOD)%MOD
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

MOD = 998244353

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

if Ds[0] != 0 or min(Ds[1:]) == 0:
    print(0)
    sys.exit()

cnt = Counter(Ds)

ans = 1
for d in range(1, max(Ds)+1):
    if cnt[d] == 0:
        ans = 0
        break
    ans *= pow(cnt[d-1], cnt[d], MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))
print((int(input())-1)//2)

Submission status: Wrong Answer

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

MOD = 998244353

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

M = max(D)
T = [0] * (M + 1)

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

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

for i in range(1, M):
  if T[i] == 0:
    print(0)
    exit()

ans = 1
for i in range(2, M + 1):
  ans = ans * (T[i - 1] ** T[i]) % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
D.sort()
ans = []
hoge = 1
for i in range(1,N):
    if D[i] == D[i-1]+1:
        ans.append(hoge)
        hoge = 1
    elif D[i] == D[i-1]:
        hoge += 1
    else:
        print(0)
        exit()
ans.append(hoge)
ret = 1
for i in range(len(ans)-1):
    ret *= pow(ans[i],ans[i+1],MOD)
    ret %= MOD
if D[0] != 0 or D[1] == 0 :
    print(0)
    exit()
print(ret)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

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

answer = 1
prev = 1
count = Counter(D)
for i in range(max(count.keys()) + 1):
    if i not in count:
        answer = 0
        break
    answer *= prev ** count[i]
    prev = count[i]
print(answer)

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 998244353

n = ri()
ls = ril()

counter = collections.Counter(ls)
if ls[0] > 0 or counter[0] > 1:
    print(0)
    exit()

res = 1
for i in range(2, max(counter.values()) + 1):
    if counter[i - 1] == 0:
        print(0)
        exit()
    res *= counter[i - 1]**counter[i]
    res %= MOD
print(res)

Submission status: Wrong Answer

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

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

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

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())
D=list(map(int,input().split()))

mod=998244353
if D[0]!=0:
  print(0)
else:
  ans=1
  for i in range(1,n):
    ans*=D[i]%mod
  print(ans%mod)

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()
x=1
ct=0
ctb=1
ans=1
mod=998244353
for i in range(1,n):
  if d[i]==x:
    ct+=1
  else:
    if x!=1:
      for j in range(ct):
        ans*=ctb
        ans%=mod
    ctb=ct
    ct=1
    x+=1
for i in range(ct):
  ans*=ctb
  ans%=mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]
mod = 998244353

def solve() :
    c = Counter(D)
    k = sorted(list(c.keys()))
    for i in range(1, len(k)) :
        if k[i] - k[i-1] != 1 :
            return 0
            
    if c[0] != 1 :
        return 0
        
    ret = 1
    for k in c.keys() :
        if k == 0 :
            continue
        
        ret = ret * pow(c[k-1], c[k], mod) % mod
    
    return ret
        
print(solve())

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
s=[0]*n
m=998244353
for i in d:
    s[i]+=1
if s[0]==1:
    c=1
    a=1
    for i in range(1,n):
        if i>0:
            c+=s[i]
            a=(a*pow(s[i-1],s[i],m))%m
        else:
            break
    if c==n:
        print(a)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

mod = 998244353

n = int(input())
d = list(map(int, input().split()))
c = Counter(d)
if c[0] != 1:
    print(0)
    exit()

k = sorted(c.keys())
prev = -1
ans = 1
for ki in k:
    if prev+1 != ki:
        ans = 0
        break
    a = c[ki-1] if ki != 0 else 1
    ans *= pow(a, c[ki], mod)
    ans %= mod
    prev = ki
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(dict(Counter(D[1:])).items())
for k, v in C:
    if k != idx:
        print(0)
        exit()
    ans *= k ** v
    idx += 1
print(ans)