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:
from collections import Counter
import sys

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

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

counter = Counter(sorted(d))
if counter[0] != 1:
    print(0)
    sys.exit()

patt = 1
for p, n in zip(counter, list(counter.keys())[1:]):
    if n > p+1:
        print(0)
        sys.exit()

    patt *= counter[p]**counter[n] % mod

print(patt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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

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

patt = 1
for p, n in zip(counter, list(counter.keys())[1:]):
    if n > p+1:
        print(0)
        sys.exit()

    patt *= counter[p]**counter[n] % mod

print(patt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
import math

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

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

counter = Counter(sorted(d))
if counter[0] != 1:
    print(0)
    sys.exit()

pn = 1
for p, n in zip(counter, list(counter.keys())[1:]):
    if n > p+1:
        print(0)
        sys.exit()

    pn *= counter[p] ** counter[n]

print(pn % mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split(" ")))
repitition = len(d)-len(set(d))
print(max((n-1-repitition)%998244353,0))

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

d = Counter(D)
Dmax = max(D)
ans = d[0]**d[1]
for i in range(1,Dmax):
	ans = (ans*d[i]**d[i+1])%998244353
if d[0] != 1:
	ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

d = Counter(D)
Dmax = max(D)
ans = d[0]**d[1]
for i in range(1,Dmax):
	ans = (ans*d[i]**d[i+1])%998244353
if d[0] == N != 1:
	ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Dmax = max(D)
ans = D.count(0)
for i in range(1,Dmax):
	d = D.count(i)
	ans *= D.count(i)**D.count(i+1)
print(ans)

Submission status: Wrong Answer

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

d.sort()
c = []
j = 0
for i in range(max(d)+1):
	tmp = 0
	while d[j] == i:
		tmp += 1
		j += 1
		if j == n:
			break
	c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print(ans%998244353)

Submission status: Wrong Answer

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

d.sort()
c = []
j = 0
for i in range(max(d)+1):
	tmp = 0
	while d[j] == i:
		tmp += 1
		j += 1
		if j == n:
			break
	c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1 and c.count(0) == 0:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print(ans%998244353)

Submission status: Wrong Answer

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

d.sort()
c = [0]
j = 1
for i in range(1, max(d)+1):
	tmp = 0
	while d[j] == i:
		tmp += 1
		j += 1
		if j == n:
			break
	c.append(tmp)

ans = 1
if d[0] == 0 and d.count(0) == 1 and c.count(0) == 1:
	for i in range(1, max(d)):
		ans = ans * (c[i]**c[i+1])
else:
	ans = 0

print(ans%998244353)

Submission status: Wrong Answer

Solution code:

def main():
    n = int(input())
    D = list(map(int, input().split()))
    nodes = [0]*n

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

    for d in D:
        nodes[d] += 1
    ans = 1

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

    print(ans)

main()

Submission status: Wrong Answer

Solution code:


def main():
    n = int(input())
    D = list(map(int, input().split()))
    nodes = [0]*n

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

    for d in D:
        nodes[d] += 1
    ans = 1

    for i in range(1, n):
        ans *= (nodes[i-1])**(nodes[i])

    print(ans)

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ctr = Counter(D)

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

ans = 1
for i in range(len(ctr)-1):
    ans *= pow(ctr[i], ctr[i+1], MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ctr = Counter(D)

if D[0]!=0:
    print(0)
    exit()
 
ans = 1
for i in range(len(ctr)-1):
    ans *= pow(ctr[i], ctr[i+1], MOD)

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N = inputInt()
    D = inputList()
    
    if D[0] != 0:
        print(0)
        sys.exit()
        
    D.sort()
    if D[1] == 0:
        print(0)
        sys.exit()
        
    maxim = D[-1]
        
    collect = {}
    for i, val in enumerate(D):
        if i == 0:
            continue
        
        if val in collect:
            collect[val] += 1
        else:
            collect[val] = 1
            
    ans = 1
    cnt = 1
    for i in range(1,maxim+1):
        if i in collect:
            ans = ans * ((cnt**collect[i]) % 998244353)
            ans = ans % 998244353
            cnt += 1
            pass
        else:
            print(0)
            sys.exit()
            
    #print(collect)
    print(ans)
    
    
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
Z = 998244353
N = int(input())
D = list(map(int,input().split()))
if D[0]>0:
    ans = 0
elif N==1:
    ans = 1
else:
    D.sort()
    if D[1]==0:
        ans = 0
    else:
        D.append(-1)
        ans = 1
        cur = 0
        n1 = 1
        n2 = 1
        for d in D[1::]:
            if d == cur:
                n2 += 1
            else:
                nn=pow(n1,n2,Z)
                ans *= nn
                n1 = n2
                n2 = 1
                cur = d
        ans%=Z
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif N==1:
    ans = 1
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for d in D[1::]:
        if d == cur:
            n2 += 1
        else:
            nn=pow(n1,n2,998244353)
            ans *= nn
            n1 = n2
            n2 = 1
            cur = d
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
D = list(map(int, input().split()))
nodes = {}
if D[0] != 0:
  print(0)
  sys.exit()
for i in D:
  v = nodes.get(i, 0)
  nodes[i] = v + 1
 
prev = 1
ans = 0
for node in nodes.values():
  if ans == 0:
    ans = prev ** node %998244353
  else:
    ans *= prev ** node %998244353
  prev = node
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif N==1:
    ans = 1
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
            if d == cur:
                n2 += 1
            else:
                nn = (n1**n2)%998244353
                ans *= nn
                n1 = n2
                n2 = 1
                cur = d
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d != 0:
            if d == cur:
                n2 += 1
            else:
                nn = (n1**n2)%998244353
                ans *= nn
                n1 = n2
                n2 = 1
                cur = d
ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d != 0:
            if d == cur:
                n2 += 1
            else:
                nn = (n1**n2)%998244353
                ans *= nn
                n1 = n2
                n2 = 1
                cur = d
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

list_str = input()
list = list_str.split()

max_num = max(list)

if int(list[0]) == 0 :
    sum = 1
else :
    sum = 0

c_list = []

for i in range(1,int(max_num) + 1):
    i_str = str(i)
    c_list.append(list.count(i_str))

for k in range(len(c_list)-1) :
    c = c_list[k] ** c_list[k+1]
    sum *= c

print (sum % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())

list_str = input()
list = list_str.split()

max_num = max(list)

sum = 0
if list[0] == 0 :
    sum = 1

c_list = []

for i in range(1,int(max_num) + 1):
    i_str = str(i)
    c_list.append(list.count(i_str))

for k in range(len(c_list)-1) :
    c = c_list[k] ** c_list[k+1]
    sum *= c

print (sum)

Submission status: Wrong Answer

Solution code:
n = int(input())

list_str = input()
list = list_str.split()

#print (list)

max_num = max(list)
#print (max_num)

#if list[0] != 0 :
    #print (0)

c_list = []

for i in range(1,int(max_num) + 1):
    i_str = str(i)
    c_list.append(list.count(i_str))

#print (c_list)


sum = 1
for k in range(len(c_list)-1) :
    c = c_list[k] ** c_list[k+1]
    sum *= c

print (sum)
'''
#print (cal)


    #print (i)
    for j in range(n):
        if list[j] == i:
            count_i += 1
            count[i].append(count_i)
'''
#print (count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(' ')]
counts = [0] * n
for i in a:
  counts[i] += 1
ans = 1 if a[0] == 0 else 0
for u, v in zip(counts, counts[1:]):
  for _ in range(v):
    ans = ans * u % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(s) for s in input().split(' ')]
counts = [0] * n
for i in a:
  counts[i] += 1
ans = 1 if a[0] == 0 else 0
for u, v in zip(counts, counts[1:]):
  ans = ans * u * v % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
d=map(int,raw_input().split())
c=[0]*n
for x in d:
  c[x] += 1
count = 0
if c[0] == 1:
	count = 1
mod = 998244353
for i in xrange(1,max(d)):
  count *= pow(c[i],c[i+1],mod)
  count %= mod
print count

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
d=map(int,raw_input().split())
c=[0]*n
for x in d:
  c[x] += 1
count = 1
mod = 998244353
for i in xrange(1,max(d)):
  count *= pow(c[i],c[i+1],mod)
  count %= mod
print count

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod=998244353
n=int(input())
D=Counter(list(map(int,input().split())))
if D[0]!=1:print(0);exit()
cnt=1
for i in range(1,max(D)+1):
    cnt *=D[i-1]**D[i]
    cnt %=mod
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=Counter(list(map(int,input().split())))
if D[0]!=1:print(0);exit()
cnt=1
for i in range(max(D)):
    cnt *=D[i]**D[i+1]
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
Q = [0]
for i in map(int, input().split()):
	if i >= len(Q):
		Q += ([0] * (i + 1 - len(Q)))
	Q[i] += 1
mod = 998244353

sum = 1
for i in range(len(Q)):
	if Q[i] == 0:
		sum = 0
		break
	if i == 0:
		if Q[i] != 1:
			sum = 0
			break
		else:
			continue
	sum *= Q[i-1] ** Q[i]
	sum %= mod

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
Q = [0]
for i in map(int, input().split()):
	if i >= len(Q):
		Q += ([0] * (i + 1 - len(Q)))
	Q[i] += 1
mod = 998244353

sum = 1
for i in range(1,len(Q)):
	sum *= Q[i-1]**Q[i]
	sum %= mod

print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
Q = [0] * 2
for i in map(int, input().split()):
	if i >= len(Q):
		Q += ([0] * (i + 1 - len(Q)))
	Q[i] += 1
mod = 998244353

sum = 1
for i in range(1,len(Q)):
	sum *= Q[i-1]**Q[i]
	sum %= mod

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

import numpy as np
MD=998244353

N=int(readline())
D=np.array(read().split(),np.int32)

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

if D[1:].min()==0:
  print(0)
  exit()
  
C=np.bincount(D)
answer=1
for i in range(len(C)-1):
  answer*=(C[i]**C[i+1])
  answer%=MD

print(answer)

Submission status: Wrong Answer

Solution code:
MD=998244353

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

import numpy as np

N=int(readline())
#print(N)
D=list(map(int,readline().split()))
#print(D)

C=[0]*(N)

for i in range(N):
  C[D[i]]+=1
#print(C)

tmp=1
for i in range(N-1):
  tmp*=(C[i]**C[i+1])
  tmp%=MD
answer=tmp

print(answer)

Submission status: Wrong Answer

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

D.sort()
count = [0]*(D[-1]+1)
ans = 1

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

if count[0] != 1 or D[0] != 0:
  print(0)
  exit()
 
for i in range(1,D[-1]+1):
    ans *= count[i-1]**count[i]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

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

D.sort()
count = [0]*(D[-1]+1)
ans = 1

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

if count[0] != 1:
  print(0)
  exit()
 
for i in range(1,D[-1]+1):
    ans *= count[i-1]**count[i]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

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

D.sort()
count = [0]*(D[-1]+1)
ans = 1

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

if count[0] != 1:
  print(0)
  exit()
 
for i in range(D[-1]+1):
    ans *= count[i-1]**count[i]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

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

D.sort()
count = [0]*(D[-1]+1)
ans = 1

if N==1 and D[0] == 0:
    print(1)
    exit()

if D[1] == 0:
    print(0)
    exit()
for i in range(N):
    count[D[i]] += 1

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

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
d = list(map(int, input().split()))
counts = [0] * (max(d) + 1)
mod = 998244353

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

if counts[0] != 1 or d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1, max(d) + 1):
        if counts[i] == 0:
            print(0)
            sys.exit()

        ans *= counts[i-1]**counts[i] % mod

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
d = list(map(int, input().split()))
counts = [0] * (max(d) + 1)

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

if counts[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1, max(d) + 1):
        if counts[i] == 0:
            print(0)
            sys.exit()

        ans *= counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0]*(max(d)+1)
    for i in d:
        counts[i] += 1

    for i in range(1, max(d)+1):
        if counts[i] == 0:
            print(0)
            sys.exit()
        
        ans *= counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0]*(max(d)+1)
    for i in d:
        counts[i] += 1

    for i in range(2, max(d)+1):
        if counts[i] == 0:
            print(0)
            sys.exit()
        
        ans *= counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0]*10**5
    for i in d:
        counts[i] += 1

    for i in range(2, 10**5):
        if counts[i - 1] == 0 and counts[i] >= 1:
            print(0)
            sys.exit()
        
        ans = ans * counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0] * 10**5
    for i in d:
        counts[i] += 1

    for i in range(2, n):
        if counts[i - 1] == 0 and counts[i] >= 1:
            print(0)
            sys.exit()
        
        ans = ans * counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0] * n
    for i in d:
        counts[i] += 1

    for i in range(2, n):
        if counts[i - 1] == 0 and counts[i] >= 1:
            print(0)
            sys.exit()
        
        ans = ans * counts[i-1]**counts[i] % 998244353

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

if d[0] != 0:
    print(0)
else:
    ans = 1
    counts = [0] * n
    for i in d:
        counts[i] += 1

    for i in range(2, n):
        if counts[i - 1] == 0 and counts[i] >= 1:
            print(0)
            sys.exit()
        
        ans *= counts[i-1]**counts[i]

    print(ans % 998244353)

Submission status: Wrong Answer

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

D.sort()

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
else:
  flg = True
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

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

  else:
    print(0)

Submission status: Wrong Answer

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

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
elif N == 1: print(0)
else:
  flg = True
  D.sort()
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

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

  else:
    print(0)

Submission status: Wrong Answer

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

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
else:
  flg = True
  D.sort()
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

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

  else:
    print(0)

Submission status: Wrong Answer

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

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
else:
  flg = True
  D.sort()
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

  if flg:
    for i in range(1,c):
      ans *= i**A[i]
    print(ans%998244353)

  else:
    print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 99824435

n = int(input())
 
D = list(map(int, input().split()))
 
dic = [0] * n
for x in D:
    dic[x] += 1
 
if dic[0] != 1 or D[0] != 0:
    print(0)
    exit()
  
ans = 1
for i in range(1, n):
    if dic[i] == 0:
        if sum(dic[i:]) == 0:
            break
        else:
            print(0)
            exit()
 
    ans = (ans * (dic[i-1] ** dic[i] % mod)) % mod
 
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

mod = 99824435

n = int(input())
 
D = list(map(int, input().split()))
 
dic = [0] * n
for x in D:
    dic[x] += 1
 
if dic[0] != 1:
    print(0)
    exit()
 
if np.array(dic == 1).sum() == n:
    print(1)
    exit()
 
ans = 1
for i in range(1, n):
    if dic[i] == 0:
        if sum(dic[i:]) == 0:
            break
        else:
            print(0)
            exit()
 
    ans = (ans * (dic[i-1] ** dic[i] % mod)) % mod
 
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

d = list(map(int,input().split()))
ans = 1
if d[0] != 0:
    ans = 0
else:
    if d.count(0) != 1:
        ans = 0
    else:
        d.sort()
        a = [0]*(max(d)+1)
        for i in d:
            a[i] += 1
        for i in range(1,max(d)):
            ans *= a[i] ** a[i+1]


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

for i in D:
  if i < N:
  	num_list[i] += 1

a = -1
    
for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
if a != -1:
  num_list = num_list[:a]

ans = 1
if num_list[0] != 1:
  print(0)
elif len(num_list) == 1:
  print(0)
else:
  for i in range(len(num_list)):
    if i > 0 and num_list[i] == 0:
      break
    elif i > 0 and num_list[i] != 0:
      for j in range(num_list[i]):
      	ans = ans * num_list[i-1]
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

d = list(map(int,input().split()))
ans = 1
if d[0] != 0:
    ans = 0
else:
    if d.count(0) != 1:
        ans = 0
    else:
        for i in range(1,max(d)):
            ans *= d.count(i)**d.count(i+1)


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

for i in D:
  if i < N:
  	num_list[i] += 1

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i in range(len(num_list)):
    if i > 0 and num_list[i] == 0:
      break
    elif i > 0 and num_list[i] != 0:
      for j in range(num_list[i]):
      	ans = ans * num_list[i-1]
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i in range(len(num_list)):
    if i > 0 and num_list[i] == 0:
      break
    elif i > 0 and num_list[i] != 0:
      for j in range(num_list[i]):
      	ans = ans * num_list[i-1]
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i in range(len(num_list)):
    if i > 0 and num_list[i] == 0:
      break
    elif i > 0 and num_list[i] != 0:
      ans = ans * (num_list[i-1] ** num_list[i])
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0 and num == 0:
      break
    elif i > 0 and num != 0:
      ans **= num
      ans *= num
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

flg = False

ans = 1
if num_list[0] != 1 or flg:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0 and num == 0:
      break
    elif i > 0 and num != 0:
      ans **= num
      ans *= num
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
d = list(map(int, input().split()))
h = [0] * n
for x in d:
  h[x] += 1

ans = 1
mod = 998244353
for i in range(1, n):
  if i > 1 and h[i] > 0 and h[i-1] == 0 and h[i-2] == 0:
    ans = 0
  ans = (ans * pow(h[i-1], h[i], mod)) % mod

if h[0] != 1:
  ans = 0

print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
d = list(map(int, input().split()))
h = [0] * n
for x in d:
  h[x] += 1

ans = 1
mod = 998244353
for i in range(1, n):
  if h[i-1] == 0 and h[i] == 0:
    ans = 0
  ans = (ans * pow(h[i-1], h[i], mod)) % mod

if h[0] != 1:
  ans = 0

print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

flg = False

for i in range(1, N):
  if D[i-1] + 2 <= D[i]:
    flg = True
    break
  elif D[i-1] + 1 == D[i]:
  	num_list.append(1)
  else:
    num_list[-1] += 1

ans = 1
if num_list[0] != 1 or flg:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0 and num == 0:
      break
    elif i > 0 and num != 0:
      ans **= num
      ans *= num
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
d = list(map(int, input().split()))
h = [0] * n
for x in d:
  h[x] += 1

ans = 1
mod = 998244353
for i in range(1, n):
  ans = (ans * pow(h[i-1], h[i], mod)) % mod

if h[0] != 1:
  ans = 0

print (ans)

Submission status: Wrong Answer

Solution code:
n = int(input().strip())
d = list(map(int, input().split()))
h = [0] * n
for x in d:
  h[x] += 1

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

if h[0] != 1:
  ans = 0

print (ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

D.sort()

counter = 0
flg = False
num_list = [1]

for i in range(1, N):
  if D[i-1] + 2 <= D[i]:
    flg = True
    break
  elif D[i-1] + 1 == D[i]:
  	num_list.append(1)
  else:
    num_list[-1] += 1

ans = 1
if num_list[0] != 1 or flg:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0:
      ans = ans ** num
      ans = ans * num
  print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

D.sort()

counter = 0
flg = False
num_list = [1]

for i in range(1, N):
  if D[i-1] + 2 <= D[i]:
    flg = True
    break
  elif D[i-1] + 1 == D[i]:
  	num_list.append(1)
  else:
    num_list[-1] += 1

ans = 1
if num_list[0] != 1 or flg:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0:
      ans = ans ** num
      ans = ans * num
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d != 0:
            if d == cur:
                n2 += 1
            else:
                nn = (n1**n2)%998244353
                ans *= nn
                n1 = n2
                n2 = 1
                cur = d
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d == cur:
            n2 += 1
        else:
            nn = (n1**n2)%998244353
            ans *= nn
            n1 = n2
            n2 = 1
            cur = d
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = sorted(list(map(int,input().split())))
ans = 1
D.append(-1)
if D[0]>0:
    ans = 0
elif D[1]==0:
    ans = 0
else:
    cur = 0
    n1 = 1
    n2 = 1
    for i,d in enumerate(D[1::],1):
        if d == cur:
            n2 += 1
        else:
            nn = (n1**n2)%998244353
            ans *= nn
            n1 = n2
            n2 = 1
            cur = d
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
E = [D.count(i) for i in range(0, max(D)+1)]
ans = 1
if E[0]!=1:
    ans = 0
else:
    for i,e in enumerate(E[1::],1):
        if e == 0:
            ans = 0
            break
        else:
            a = E[i-1]
            ans *= a**e
print(ans%998244353)

Submission status: Wrong Answer

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

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

Ds = [d for d in Ds if d >= 2]

a = 1
for d in Ds:
    a *= d
print(a)