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:
M = 998244353
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a = a*pow(k[j-1],k[j],M)%M
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
M = 998244353
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a *= pow(k[j-1],k[j],M)
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
M = 998244353
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a *= pow(k[j-1],k[j])
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a%M)

Submission status: Wrong Answer

Solution code:
M = 998244353
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a *= pow(k[j-1],k[j],M)
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a%M)
print(k)

Submission status: Wrong Answer

Solution code:
M = 998244353
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a *= pow(k[j-1],k[j])
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a%M)
print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D)+1)
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)+1):
      k[i] = D.count(i)
    for j in range(0,len(k)):
      a *= pow(k[j-1],k[j])
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a%998244353)
print(k)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0 or a.count(0)!=1:
  print(0)
else:
  a.sort()
  i=1
  j=1
  p=1
  q=0
  r=1
  while i<n:
    while a[i]==j:
      q+=1
      i+=1
      if i==n:
        break
    j+=1
    r*=p**q
    p=q
    q=0
  print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
k = [0]*(max(D))
a = 1
l = 0
if D[0] == 0:
  if D.count(0) == 1:
    for i in range(0,max(D)):
      k[i] = D.count(i+1)
    for j in range(1,len(k)+1):
      a *= j**k[j-1]
  else:
    l += 1
else:
  l += 1
if l > 0:
  print(0)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
D_max = max(D)
ans = 1
flag = 1
mod = 998244353
for i in range(D_max+1):
  cnt_D = D.count(i)
  if cnt_D == 0:
    print(0)
    break
  else:
    ans *= (flag**cnt_D % mod)
    flag = cnt_D
    if i == D_max:
      print(ans)

Submission status: Wrong Answer

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

ma = max(d)
l = [0] * n
ans = 1

#  1番上の頂点が無ければ0
if d[0] != 0:
    print(0)
    exit()

#  0~maxがそれぞれ何個あるか
for e in d:
    l[e] += 1

#  1番上の頂点が複数個だと0
if l[0] != 1:
    print(0)
    exit()

for i in range(ma):
    #  l[i]は辺の数でl[i+1]はノードの数
    ans = l[i] ** l[i+1]
    ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

mi = min(d)
ma = max(d)
l = [0] * n
ans = 1


if mi == ma:
    print(0)
    exit()

#  0~maxがそれぞれ何個あるか
for e in d:
    l[e] += 1

for i in range(ma):
    #  l[i]は辺の数でl[i+1]はノードの数
    ans = l[i] ** l[i+1]
    ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

min_d = min(d)
max_d = max(d)
sum = 1

if min_d == max_d:
    print(0)
else:
    for i in range(min_d+1, max_d+1):
        s = d.count(i-1)
        t = d.count(i)
        sum *= s**t
        
    print(sum)

Submission status: Wrong Answer

Solution code:
def find(D):
    if D[0]!=0:
        return 0
    
    count=[0 for _ in range(len(D))]
    MAX=max(D)
    
    ans=1
    if count[0]!=1:
        return 0
    
    for i in range(1,MAX+1):
        ans=ans*pow(count[i-1],count[i],998244353)
        ans%=998244353
    return ans
N=int(input())
D=list(map(int,input().strip().split()))
print(find(D))

Submission status: Wrong Answer

Solution code:
def find(D):
    if D[0]!=0:
        return 0
    
    count=[0 for _ in range(len(D))]
    MAX=max(D)
    
    ans=1
    for i in range(len(count)):
        if count[i]>0:
            MAX=i
    
    if count[0]!=1:
        return 0
    
    for i in range(1,MAX+1):
        ans=ans*pow(count[i-1],count[i],998244353)
        ans%=998244353
    return ans
N=int(input())
D=list(map(int,input().strip().split()))
print(find(D))

Submission status: Wrong Answer

Solution code:
def find(D):
    count=[0 for _ in range(len(D))]
    for x in D:
        count[x]+=1
    
    ans=1
    MAX=0
    for i in range(len(count)):
        if count[i]>0:
            MAX=i
    
    if count[0]!=1:
        return 0
    
    for _ in range(1,MAX+1):
        ans*=pow(count[_-1],count[_],998244353)
        ans%=998244353
    return ans
N=int(input())
D=list(map(int,input().strip().split()))
print(find(D))

Submission status: Wrong Answer

Solution code:
def find(D):
    count=[0 for _ in range(len(D))]
    for x in D:
        count[x]+=1
    
    ans=1
    MAX=0
    for i in range(len(count)):
        if count[i]>0:
            MAX=i
    
    if count[0]!=1:
        return 0
    
    for _ in range(1,MAX+1):
        if count[_]==0:
            return 0
        ans*=pow(count[_-1],count[_],998244353)
        ans%=998244353
    return ans
N=input()
D=list(map(int,input().strip().split()))
print(find(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
Trees = [0 for i in range(N)]
count = 1

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

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

for j in range(2,N):
    if Trees[j] == 0:
        break
    count *= Trees[j-1] * j-1

result = count % 998244353
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
ma = max(D)
l = [0]*n
ans = 1

if D[0] != 0:
    print(0)
    exit()
    
for e in D:
    l[e] += 1

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

for i in range(ma):
    ans = ans ** l[i+1] * l[i+1]
    ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int,input().split()))
ma = max(D)
l = [0]*n
ans = 1

if D[0] != 0:
    print(0)
    exit()
    
for e in D:
    l[e] += 1

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

for i in range(ma):
    ans = ans ** l[i+1] * l[i+1]
print(ans%998244353)

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 z[i] == 0:
			print(0)
			return
	if(d[0]!=0 and z[0] != 1):
		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:
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 z[i] == 0:
			print(0)
			return
	if(d[0]!=0):
		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:
from collections import Counter as co
n=int(input())
l=sorted(list(co(sorted(list(map(int,input().split())))).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n or pre*2<s:
    print(0)
    exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if pre*2<s:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = i = 1
  x = c.get(i)
  while x and i < n + 2:
    n -= x
    r = r * pow(p, x, M) % M
    i += 1; p = x; x = c.get(i)
print((r, 0)[n > 1])

Submission status: Wrong Answer

Solution code:
n = int(input())
d_1 = input().split()
d = [int(s) for s in d_1]

c = [d.count(i) for i in d]

if d[0] != 0:
  print(0)
else:
  M = max(d) + 1
  ans = 1
  for i in range(M-2):
    ans = ans * pow(c[i+1], c[i+2], 998244353) % 998244353
  print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial
def ncr(n,r):
 a = factorial(n) // factorial(r) // factorial(n - r)
 return a
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def solve():
  n = int(input())
  d = list(int(i) for i in input().split())
  mod = 998244353
  query = [0]*n
  length = 0
  for i in range(n):
    tmp = d[i]
    length = max(tmp,length)
    query[tmp] += 1
  ans = query[0]
  now = ans
  if now == 0:
    print(0)
    exit()
  for i in range(1,length+1):
    next = query[i]
    if next == 0:
      print(0)
      exit()
    if now == 1:
      ans *= next
    else:
      if next == 1:
        ans *= 1
      else:
        ans *= ncr((next+now-1),now-1)
    ans %= mod
    now = next
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
from math import factorial
def ncr(n,r):
 a = factorial(n) // factorial(r) // factorial(n - r)
 return a
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def solve():
  n = int(input())
  d = list(int(i) for i in input().split())
  mod = 998244353
  query = [0]*n
  length = 0
  for i in range(n):
    tmp = d[i]
    length = max(tmp,length)
    query[tmp] += 1
  ans = query[0]
  now = ans
  if now == 0:
    print(0)
    exit()
  for i in range(1,length+1):
    next = query[i]
    if next == 0:
      print(0)
      exit()
    if next == 1:
      ans *= now
      now = next
      continue
    if now == 1:
      ans *= next
    else:
      ans *= ncr((next+now-1),now-1)
    ans %= mod
    now = next
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
from math import factorial
def ncr(n,r):
 a = factorial(n) // factorial(r) // factorial(n - r)
 return a
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def solve():
  n = int(input())
  d = list(int(i) for i in input().split())
  mod = 998244353
  query = [0]*n
  length = 0
  for i in range(n):
    tmp = d[i]
    length = max(tmp,length)
    query[tmp] += 1
  ans = query[0]
  now = ans
  if now == 0:
    print(0)
    exit()
  for i in range(1,length+1):
    next = query[i]
    if next == 0:
      print(0)
      exit()
    if next == 1:
      ans += now
      now = next
      continue
    if now == 1:
      ans *= next
    else:
      ans *= ncr((next+now-1),now-1)
    ans %= mod
    now = next
  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

DD = collections.Counter(D)
max_key = max(DD.keys())
result = 1
last_v = 0
for k in range(max_key + 1):
    if not k in DD:
        print(0)
        sys.exit()
    v = DD[k]
    if k == 0:
        last_v = v
        continue
    result *= last_v ** v
    last_v = v
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

DD = sorted(collections.Counter(D).items())
result = 1
last_v = 0
for k, v in DD:
    if k == 0:
        last_v = v
        continue
    result *= last_v ** v
    if result == 0:
        print(0)
        sys.exit()
    last_v = v
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

if D[0] != 0 or D[1] == 0:
    print(0)
    sys.exit()
DD = sorted(collections.Counter(D).items())
result = 1
last_v = 0
for k, v in sorted(DD):
    if k == 0:
        last_v = v
        continue
    if v == 0:
        print(0)
        sys.exit()
    result *= last_v ** v
    last_v = v
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

if D[0] != 0 or D[1] == 0:
    print(0)
    sys.exit()
DD = collections.Counter(D)
result = 1
for i in range(N - 1):
    amount = DD[i] ** DD[i + 1]
    if amount == 0:
        print(0)
        sys.exit()
    result *= amount
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections

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

if D[0] != 0 or D[1] == 0:
    print(0)
    sys.exit()
DD = collections.Counter(D)
result = 1
for i in range(N - 1):
    amount = DD[i] ** DD[i + 1]
    if amount == 0:
        print(0)
        sys.exit()
    result *= amount
print(result)

Submission status: Wrong Answer

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


def modPow(x, n, BIGMOD):
    ans = 1
    while n >= 1:
        if bin(n & 1) == bin(1):
            ans = (ans * x) % BIGMOD
        x = x * x % BIGMOD
        n = n >> 1
    return ans % BIGMOD


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

Sum = 1

if x[0] != 1:
    print(0)
else:

    for i in range(1,len(x)-1):

        Sum = (Sum * modPow(x[i], x[i+1], 998244353)) % 998244353

    print(Sum % 998244353)

Submission status: Wrong Answer

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


def modPow(x, n, BIGMOD):
    ans = 1
    while n >= 1:
        if bin(n & 1) == bin(1):
            ans = (ans * x) % BIGMOD
        x = x * x % BIGMOD
        n = n >> 1
    return ans % BIGMOD


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

Sum = 1

if x[0] != 1:
    print(0)
else:

    for i in range(len(x)-1):

        Sum = (Sum * modPow(x[i], x[i+1], 998244353)) % 998244353

    print(Sum % 998244353)

Submission status: Wrong Answer

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

def modPow(x, n, BIGMOD):
    ans = 1
    while n >= 1:
        if bin(n & 1) == bin(1):
            ans = (ans * x) % BIGMOD
        x = x * x % BIGMOD
        n = n >> 1
    return ans % BIGMOD

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

Sum = 1

if x[0] != 1:
    print(0)
else:

    for i in range(len(x)):
    
        if i != 0:
            Sum = (Sum * modPow(x[i - 1], x[i], 998244353))%998244353
    
    print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list(map(int, input().split()))
a = 1
M = 998244353
if li.count(0) == 0:
  print(0)
elif li.count(0) == 1:
  for i in range(1, max(li)):
    a *= (li.count(i)**li.count(i+1))
    print(a%M)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
import numpy as np
D=np.array(D)
M=1
if D[0]!=0:
    print(0)
else:
    for i in range(max(D)-1):
        M=M*np.count_nonzero(D==i+1)**np.count_nonzero(D==i+2)
    print(M)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if D[0] != 0 or D.count(0) > 1:
    print(0)
else:
    c = Counter(D)
    for key in c:
        if key == 0:
            continue
        elif key-1 in c == False:
            ans = 0
            break
        else:
            ans = ans * c[key-1] ** c[key]
    print(ans)

Submission status: Wrong Answer

Solution code:
N =int(input())
D = [int(x) for x in input().split()]
cnt = [0]*(N)
if D[0]!=0:
  print(0)
  exit()
for i in range(N):
  cnt[D[i]]+=1
ans = 1
if cnt[0]!=1:
  print(0)
  exit()
a = 0
b = 0
for i in range(1,N-1):
  if cnt[i]==0 and a==0:
    a=i
    b+=1
  if a!=0 and cnt[i]!=0:
    print(0)
    exit()
  elif a!=0 and cnt[i]==0:
    b+=1
  ans*=cnt[i-1]**cnt[i]
#print(cnt,a,b)
if N-a==b or a==b==0:
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    if arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount
    if result > 998244353:
      result = result % 998244353
    #print(pre, curCount, preCount, result)
  return result%998244353
 
print(calc(D))

Submission status: Wrong Answer

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


def main():
    from collections import Counter

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

    # KeyInsight
    # 条件を満たす個数：距離Diの頂点に対して親の個数の数だけ辺が張れるか，と言い換え

    # 気がつけた点
    # D1は0，それ以外は1l以上であるかどうかで場合分け
    # サンプルから組み合わせを愚直に数えた

    # 気がつけなかった点
    # 各距離における組み合わせを効率的に求める方法．重複組み合わせを数えようとしていた
    if d[0] == 1 or (0 in d[1:]):
        print(0)
        exit()

    ans = 1
    mod = 998244353

    for i in c.keys():
        if i >= 2:
            ans *= c[i - 1] ** c[i]
            ans %= mod

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    if arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount % 998244353
    #print(pre, curCount, preCount, result)
  return result%998244353
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    if arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount
    #print(pre, curCount, preCount, result)
  return result%998244353
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == 0:
      return 0
    if D[i] == D[i-1]:
      result = result * preCount
      curCount += 1
    elif D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
      result = result * preCount % 998244353
    else:
      return 0
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == 0:
      return 0
    if D[i] == D[i-1]:
      result = result * preCount
      curCount += 1
    elif D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
      result = result * preCount
    else:
      return 0
  return result%998244353
 
print(calc(D))

Submission status: Wrong Answer

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

def main():
  N = int(input())
  vD = list(map(int, input().split()))
  MOD = 998244353

  if vD[0]!=0:
    print(0)
    return

  vD.sort()

  res = 1
  p = -1
  pcnt = 1
  ccnt = 1
  for d in vD:
    if d==p+1:
      pcnt = ccnt
      ccnt = 1
    elif d==p:
      ccnt += 1
    else: # d>=p+2
      print(0)
      return

    res *= pcnt
    res %= MOD
    p = d

  print(res)

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    elif arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return result
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0:
      return 0
    elif arr[i] == arr[i-1]:
      curCount += 1
    elif arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(arr):
  if arr[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(arr)):
    if arr[i] == 0 or arr[i] > arr[i-1] + 1:
      return 0
    if arr[i] == arr[i-1]:
      curCount += 1
    if arr[i] == arr[i-1] + 1:
      preCount = curCount
      curCount = 1
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

n = max(D)

c = 1
c_m = np.count_nonzero(D == 0)
for i in range(1, n+1):
  c_p = np.count_nonzero(D == i)
  c *= c_m ** c_p
  c_m = c_p


print(c)

Submission status: Wrong Answer

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

n = max(D)

c = 1
for i in range(n):
  c *= D.count(i) ** D.count(i+1)

print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(d)
if c[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1, max(d)+1):
        ans *= c[i-1] ** c[i]
        ans = 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

c = Counter(d)
if c[0] != 1 or d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1, max(d)+1):
        ans *= (c[i-1] ** c[i]) % mod
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(d)
if c[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1, max(d)+1):
        ans *= (c[i-1] ** c[i]) % mod
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
p=0
if D[0]!=0:
    print(0)
else:
    for i in range(N):
        if p<=D[i]:
            p=D[i]
        else:
            p=p

    List=[]
    for i in range(p+1):
         y=0
         for j in range(N):
            if D[j]==i:
                y=y+1
            else:
                y=y
         List.append(y)
    
    t=0
    for i in range(p):
         if List[i]==0:
             t=t+1
         else:
             t=t
 
    if t!=0:
        print(0)
    elif List[0]!=1:
         print(0)
    else:
        count=1
        for i in range(p):
             count=count*(List[i]**List[i+1])
        print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
p=0
if D[0]!=0:
    print(0)
else:
    for i in range(N):
        if p<=D[i]:
            p=D[i]
        else:
            p=p

    List=[]
    y=0
    for i in range(p+1):
         for j in range(N):
            if D[j]==i:
                y=y+1
            else:
                y=y
            List.append(y)

    t=0
    for i in range(p):
         if List[i]==0:
             t=t+1
         else:
             t=t

    if t!=0:
        print(0)
    elif List[0]!=1:
         print(0)
    else:
        count=1
        for i in range(p-1):
             count=count*(List[i]**List[i+1])
        print(count-1)

Submission status: Wrong Answer

Solution code:

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

ans=1


for v in D:
  if v==0 and D.index(v)==0:
    continue
  else:
    ans*=v
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
p=0
if D[0]!=0:
    print(0)
else:
    for i in range(N):
        if p<=D[i]:
            p=D[i]
        else:
            p=p

    List=[]
    y=0
    for i in range(p+1):
         for j in range(N):
            if D[j]==i:
                y=y+1
            else:
                y=y
            List.append(y)

    t=0
    for i in range(p):
         if List[i]==0:
             t=t+1
         else:
             t=t

    if t!=0:
        print(0)
    elif List[0]!=1:
         print(0)
    else:
        count=1
        for i in range(p-1):
             count=count*(List[i]**List[i+1])
        print(count)

Submission status: Wrong Answer

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

c=Counter(D)
ans=1


for v in c:
  if v==0:
    continue
  else:
    ans*=(v**c[v])   
    
print(ans)