Problem:


Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

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

Ans = 0
number = 1
n_count = 0
b_count = 1

newD = sorted(D)
if N == 1:
  Ans = 1
  print(Ans)
  sys.exit()

if newD[0] != 0 or newD[1] != 1:
  print(Ans)
  sys.exit()
else:
  
  for i in range(1,N):
    if newD[i] == number:
      n_count = n_count + 1
    elif newD[i] == number + 1:

      if number == 1:
        Ans = 1
        #print(Ans)
      else:
        Ans = Ans * (b_count ** n_count)
        if Ans > 998244353:
          Ans = Ans % 998244353
        #print(Ans)
        
      number = number + 1
      b_count = n_count
      n_count = 1
    else:
      Ans = 0
      print(Ans)
      sys.exit()

  if number == 1:
    Ans = 1
  else:
    Ans = Ans * (b_count ** n_count)
    Ans = Ans % 998244353
  print(Ans)

Submission status: Wrong Answer

Solution code:
import heapq
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
q = []
if d[0] != 0:
  print(0)
else:
  for x in d[1:]:
    heapq.heappush(q, x)
  prev = 0
  x = 0
  y = 1
  ans = 1
  for i in range(n-1):
    a = heapq.heappop(q)
    if a == prev:
      x += 1
    elif a == prev + 1:
      x += 1
      ans = ans * (y ** x) % mod
      y = x
      x = 0
    else:
      print(0)
      break
    prev = a
  else:
    x += 1
    ans = ans * (y ** x) % mod
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
import collections
cnt = collections.Counter(D[1:])
maxs = 998244353
res = 1
flag = True
scnt = sorted(cnt.items(), key=lambda x: x[0])
for i in range(1, len(scnt)):
    if scnt[i][0] != scnt[i-1][0] + 1:
        flag = False
        break
    res = (res * (scnt[i-1][1] ** scnt[i][1])) % maxs
print(res) if flag else 0

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    datas, counts = [_ for _ in range(max(A) + 1)], []
    for i in range(max(A) + 1):  # i = 0 ~ max(A)
        if i not in A:
            print(0)
            exit()
        else:
            counts.append(A.count(i))
    return datas, counts


N = int(input())
D = list(map(int, input().split()))
D_datas, D_counts = ContinueCnt(D)
# print(D_datas, D_counts)  # for debug
INF = 998244353

# first check zero
if D_counts[0] != 1:
    print(0)
    exit()

ans = 1
# check 1 ~ max(D)
for i in range(1, max(D_datas) + 1):
    ans *= D_counts[i - 1] ** D_counts[i]
    ans %= INF
    # print("now = ", ans)  # for debug

print(ans % INF)

Submission status: Wrong Answer

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-09 21:20:16(JST)
### modules
## from standard library
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator
## from external libraries
# import scipy.special   
# import scipy.misc      
# import numpy as np 

mod = 998244353

def main():
    n, *d = (int(x) for x in sys.stdin.read().split())
    
    if d[0] != 0:
        print(0)
        exit()

    del d[0]

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

    d.sort()
    
    maximum = d[-1]
    for i in range(1, maximum + 1):
        if not i in d:
            print(0)
            exit()


    c = collections.Counter(d)
    
    total =  1
    for b, e in sorted(c.items()):
        if b != maximum:
            nex = c[b+1]
            total *= e ** nex
    print(total)




if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Wrong Answer

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

X = 998244353

l_max = max(D)

def f():
    if D[0] != 0:
        print(0)
        return
    L = [0] * (l_max+1)
    for d in D:
        L[d] += 1 

    ans = 1
    L = [1] + L
    #print(L)

    for i in range(1, len(L)):
        if L[i] == 0:
            print(0)
            return
        ans = ans * (L[i-1] ** L[i])
    print(ans)
    
f()

Submission status: Wrong Answer

Solution code:
def f():
    n = int(input())
    d = [int(s) for s in input().split()]
    d.sort()
    if d[0] != 0 or d[1] == 0:
        return 0
    count = [1]
    v = 1
    c = 0
    for i in range(1,n):
        if d[i] != v:
            if c == 0:
                return 0
            count.append(c)
            v += 1
            c = 1
        else:
            c += 1
    count.append(c)

    ans = 1
    last = 1
    for cur in count:
        ans *= (last**cur)%998244353
        last = cur
    return ans%998244353

print(f())

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

# a = comb(n, r)

# import pow

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 998244353
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ds = LI()
    c = Counter(ds)
    max_ = max(ds)
    ans = 1
    before = 1
    if c.get(0) != 1:
        print(0)

    for i in range(max_ + 1):
        if i not in c:
            print(0)
            return
        now = c.get(i)
        ans *= pow(before, now, MOD)
        ans = ans % MOD
        before = now
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
# sD = sorted(set(D))
# for i in range(len(sD)):
#     if i != sD[i]:
#         print(0)
#         exit()
# count = [0] * len(sD)
# for i in range(len(D)):
#     count[D[i]] += 1
#
# if count[0] != 1 or D[0] != 0:
#     print(0)
#     exit()
#
# ans = 1
# # print(count)
# if len(sD) == 1:
#     print(1)
# else:
#     for i in range(1, len(sD)):
#         ans *= count[i - 1] ** count[i]
#     print(ans)

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

if count[0] != 1 or D[0] != 0:
    print(0)
elif mN == 0:
    print(1)
else:
    ans = 1
    for i in range(1, len(count)):
        if count[i]:
            ans *= count[i - 1] ** count[i]
        else:
            print(0)
            exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
def calc_pow_ex(a,n):
    if a == 0:
        return 0
    else:
        return a**n

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


D.sort()

count = [0] * len(D)
flag = [0] * len(D)
a = 0
for i,d in enumerate(D):
    while not d == a:
        a += 1
    count[a] += 1
    flag[a] = 1

#print(count,flag)

ans = 1
stop = sum(flag) - 1

if not count[0] == 1:
    print(0)
    exit()
else:
    for i , x in enumerate(count):
        if i > 0:
            #print(i,x,flag[i],ans)
            if flag[i] > 0:
                ans *= calc_pow_ex(i,x)
                #print(ans)
            else:
                if i >= stop:
                    print(ans)
                else:
                    print(0)
                break

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
E = [i-D[0] for i in D[1:]]
d = dict(Counter(sorted(E)))
sum_=1
temp=1
i_temp = 0
if len(d) ==1:
    print(0)
    sys.exit()
for i in d.keys():
    if i-i_temp !=1:
        print(i,i_temp)
        print(0)
        sys.exit()
    sum_ = (sum_ * temp ** d[i]) % lim
    temp = d[i]
    i_temp = i
print(sum_)

Submission status: Wrong Answer

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

import numpy as np

if D[0]!=0:
  print(0)
else:
  print(np.prod(D[1:N+1]))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=list(map(int,input().split()))

temp=[0]*(max(l)+1)
for item in l:
    temp[item]+=1

if temp[0]==0:
    print(0)
    exit()

ans=1
for i in range(2,len(temp)):
    #print(ans)
    ans=ans*temp[i-1]**temp[i]
print(ans)

Submission status: Wrong Answer

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

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

count = 1
dmax = max(d)
num_array = [0] * (dmax+1)

for i in range(len(d)):
    num_array[d[i]] += 1

for i in range(1, dmax+1):
    count *= i ** num_array[i]
print(count % 998244353)

Submission status: Wrong Answer

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

key = max(D) + 1
count_list = [0] * key

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

counter = 1
if 0 in count_list:
    counter = 0

if count_list[0] != 1:
    counter = 0

for i in range(1, key - 1):
    counter *= count_list[i]**count_list[i + 1]

print(counter%998244353)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

x.pop(0)


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(len(x)-1):
    pre_num = x[i][1]
    forward_num = x[i+1][1]
    if pre_num == 1:
        ans *= forward_num
    elif forward_num == 1:
        ans *= pre_num
    else:
        ans *= math.factorial(pre_num) * cmb(forward_num+1, pre_num-1)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
M = 998244353
N = int(input())
# D = list(map(int, input().split()))
ans = 1
counter = Counter(map(int, input().split()))
pre_c = 1
for i, (n, c) in enumerate(sorted(counter.items())):
    if i != n:
        ans = 0
        break
    elif n == 0:
        continue
    ans *= n**c
print(ans % M)

Submission status: Wrong Answer

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

n=int(input())
d=list(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

if c[0]>1:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

a=list(map(int,input().split()))

kanou=True

if(a[0]!=0):
    print(0)
    kanou=False

a.sort()
#print(a)


cnt=[0]*n

if(kanou):
    if(n==1):
        if(a[0]==0):
            print(1)
        else:
            print(0)
        kanou=False
    elif(a[0]!=0 or a[1]==0):
        print(0)
        kanou=False



if(kanou):
    cnt[0]=1
    temp=0
    for c in a:
        if(c==0):
            continue
        if(c==temp):
            cnt[c]+=1
        elif(c==temp+1):
            cnt[c]+=1
            temp+=1
        else:
            kanou=False
            print(0)
            break

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

    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
if a[0]!=0:
    print(0)
    exit()

b = [0]*n
for i in a: b[i]+=1

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

ans = 1
i = 0
while i<n-1:
    if b[i]==0:
        if sum(b[i:])>0:
            print(0)
            exit()
        else:
            break
    ans *= b[i]**b[i+1]
    i += 1

print(ans%998244353)

Submission status: Wrong Answer

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

N = I()
a = IL()
a.sort()
num = max(a)
aset = [0 for i in range(num+2)]


for i in a:
  aset[i] += 1
#print(aset)
if aset[0] == 1:
  ans = 1
  for i in range(1,num+1):
    if aset[i] == 0:
      print(0)
      exit()
    else:
      ans = (ans * aset[i-1]**aset[i]) %mod
  print(ans)

else:
  print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if len(set(D))==1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(0,max(D)+1):
        #print(cnt[i],tmp)
        if cnt[i] == 0:
            c = tmp**1
            ans *= c
            tmp = 1
        else:
            c = tmp**cnt[i]
            ans *= c
            tmp = cnt[i]
    print(ans % mod)

Submission status: Wrong Answer

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

  return res

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

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys

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

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

d.sort()
dd = []
c = 1
for i in range(1, n):
    if d[i-1]==d[i]:
        c += 1
    else:
        dd.append(c)
        c = 1
dd.append(c)

ans = 1
for i in range(1, len(dd)):
    ans *= dd[i-1] ** dd[i]

ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n, *d = map(int, open(0).read().split())
a = [0] * (n + 1)
for x in d:
	a[x] += 1
ans = 1
mod = 998244353
if a[0] != 1:
	print(0)
	exit()
if n == 1:
	print(1)
	exit()
ans = 1
bef = 0
for x in a[:0:-1]:
	if x == 0:
		continue
	ans *= x * bef
	if ans == 0:
		ans = 1
	ans %= mod
	bef += x
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n=int(input())
	D=list(map(int,input().split()))
	
	
	if D[0]!=0:
		print(0)
		exit(0)
	
	if len(D)==1:
		print(1)
		exit(0)
		
		
	D.sort()
	
	if D[1]!=1:
		print(0)
		exit(0)
	
	ans=1
	
	li=[0]*n
	
	for i in range(n):
		li[D[i]]+=1
	
	for i in range(1,n):
		ans*=li[D[i]-1]
	
	print(ans)
if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

def calc():
    if D[0] != 0:
        return 0
    if sum(D) < N-1:
        return 0
    
    c = Counter(D)
    ret = 1
    tmpkey = 0
    tmpvalue = 0
    for key in sorted(c.keys()):
        if key - tmpkey >= 2:
            return 0
        if key > 0:
            ret *= (tmpvalue ** c[key]) % MOD
            ret %= MOD
        tmpkey = key
        tmpvalue = c[key]
    return ret

print(calc())

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))

lens = [0] * N

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

total = 1
prev_l = 1
for i, l in enumerate(lens):
    if prev_l == 0 and l != 0:
        total = 0
        break
    if i == 0:
        prev_l = l
        if l != 1:
            total = 0
            break
        continue
    total *= ((prev_l**l)%MOD)
    prev_l = l

print(total)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(int, input().split()))
Ns = [0]*N
for D in Ds:
  Ns[D] += 1
#print(Ns)
if Ns[0] != 1:
  print(0)
  exit()
r = 1
p = 1
for n in Ns:
  #r = r*(p**n)%998244353
  for i in range(n):
    r = r*p%998244353
  p = n
print(r)

Submission status: Wrong Answer

Solution code:
from sys import exit

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

D.sort()
t = D[0]
for i in range(len(D)):
    D[i] -= t

c = {}
for i in D:
    if i in c:
        c[i] += 1
    else:
        c[i] = 1

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

result = 1
for i in range(1, N + 1):
    if i not in c:
        if D[-1] == i - 1:
            break
        else:
            print(0)
            exit()
    result = result * (c[i - 1] ** c[i]) % 998244353
print(result)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
a = sorted(d)
start = 0
counta = 0
countb = 1
ans = 1
for i in a:
    if(start == i):
        counta += 1
    else:
        ans *= countb ** counta
        start = i
        countb = counta
        counta = 1
ans *= countb ** counta
print(ans%998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def one_str():
    return input()

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

N=one_int()
D=many_int()

num=998244353


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

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True
if flg:
    sums=0

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

Submission status: Wrong Answer

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

m = {}
for item in d:
    if item in m:
        m[item] += 1
    else:
        m[item] = 1

if (0 in m) and (m[0] == 1):
    prev = 1
    s = 1
    visited = 1
    for i in range(1, 10 ** 5 + 1):
        if not i in m:
            break
        v = m[i]
        visited += v

        s *= (prev ** v)
        s = s % 998244353
        prev = v
    
    if visited != n:
        s = 0
else:
    s = 0

print(s)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
D_count=sorted(Counter(D).items())
cnt=1
x,y=0,0
for i in range(max(D)+1):
    if i==0:
        if i==D_count[i][0]:
            x=D_count[i][1]
            continue
        else:
            print(0)
            exit()
    else:
        if i==D_count[i][0]:
            y=D_count[i][1]
            cnt *=(x**y)%(998244353)
        else:
            print(0)
            exit()
    x=D_count[i][1]
print(cnt)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

D.sort()
E=[]

a=0
b=0
while True:
   b=D.count(a)
   if(b==0):
       break
   E.append(b)
   a+=1
if(N!=int(sum(E))):
    print(0)
else:
    c=1
    for i in E:
       c*=i
    print(c//998244353)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
d = list( map(int, input().split()) )
MOD = 998244353

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0
    else:
        res = 1
        for i in range(2, iter+1):
            if c[i] == 0:
                return 0
            else:
                res *= c[i-1]**c[i] % MOD
        return res
res = count(c, max(d))
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()
D = D[1:]
DD = Counter(D)
#print(DD)
MOD = 998244353
ans = 1
if len(DD) == 1:
    print(1)
    exit()
for i in range(2,len(DD)+1):
    #ans *= (DD[i-1] ** DD[i])
    #ans %= MOD
    ans *= pow(DD[i-1],DD[i],MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
a = sorted(d)
print(a)
start = 0
counta = 0
countb = 1
ans = 1
for i in a:
    if(start == i):
        counta += 1
    else:
        ans *= countb ** counta
        start = i
        countb = counta
        counta = 1
ans *= countb ** counta
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
c=0
a = list(map(int,input().split()))
a.sort()
mem = {}
mem['-1']=1
count = 1
for v in a:
    need = v-1
    if str(need) in mem:
        count *= mem.get(str(need))
        count %=mod
    else:
        count = 0
        break
    if str(v) in mem:
        mem[str(v)] = mem.get(str(v))+1
    else:
        mem[str(v)] = 1
if n == 1:
    raise Exception('Error 1')
elif '0' in mem and mem.get('0')>1:
    print(0)
else:
    print(count%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list(map(int, input().split()))
a = 1
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))
    if li.count(i) == 0:
      print(0)
      break
  print(a)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

#lines = stdin.readlines()
def rint():
    return map(int, sys.stdin.readline().split())

def input():
    return sys.stdin.readline().rstrip('\n')

def oint():
    return int(input())

N = oint()

d = list(rint())

d.sort()


if d[0] != 0:
    print(0)
    exit()
if N > 1 and d[1] == 0:
    print(0)
    exit()

n = 1
c = 0
cprev = 1
ans = 1
for i in range(1, N):
    if d[i] == n:
        c+=1
    elif d[i] != n+1:
        print(0)
    else:
        ans = (ans* pow(cprev, c, 998244353))%998244353
        n += 1
        cprev = c
        c = 1

ans = (ans* pow(cprev, c, 998244353))%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
A = list(map(int,input().split()))
D = [1 for _ in range(max(A)+1)]
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

D[1] = A.count(1)
ans = 1
if A[0] > 0 or D[0] > 1:
    print(0)
else:
    for i in range(2,max(A)+1):
        #D[i] = A.count(i)
        ans *= (A.count(i-1)**A.count(i))%mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
D = list(map(int,input().split()))
D_counter = collections.Counter(D)
D_max = max(D)
ans = 1
if D[0] != 0:
    ans = 0
else:
    for n in range(2,D_max+1):
        if D_counter[n] != 0:
            for d in range(D_counter[n]):
                ans = ans * D_counter[n-1]
                ans = ans % 998244353
        else:
            ans = 0
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

d.sort()
dd = []
c = 1
for i in range(1, n):
    if d[i-1]==d[i]:
        c += 1
    else:
        dd.append(c)
        c = 1
dd.append(c)

ans = 1
for i in range(1, len(dd)):
    ans *= dd[i-1] ** dd[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
shirushi=0
if d[0]!=0:
	shirushi=1
	print(0)
else:
	d.sort()
	kotae=1
	kosulist=[]
	kazoe=1
	for i in range(1,n):
		if d[i]==d[i-1]:
			kazoe+=1
		else:
			kosulist.append(kazoe)
			kazoe=1
	kosulist.append(kazoe)
	for i in range(len(kosulist)-1):
		kotae=kotae*(kosulist[i]**kosulist[i+1])
	print(int(kotae))

Submission status: Wrong Answer

Solution code:
import collections


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

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, D):
    M = Mod(998244353)
    C = Counter(D)
    ans = 1
    for i in range(1, max(D)+1):
        if C[i-1] == 0:
            return 0
        ans = M.mul(ans, M.pow(C[i-1], C[i]))
    return ans


def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 998244353
kaizyo = [1, 1]
for i in range(2, 100005):
    kaizyo.append(kaizyo[-1]*i % mod)

# print(kaizyo[:10])


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

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

prime_D = set(D)
prime_D = list(prime_D)
counter = {}

for i in range(len(prime_D)):
    counter[prime_D[i]] = 0

for i in range(len(D)):
    counter[D[i]] += 1  # 数を数えた

counter = sorted(counter.items(), key=lambda x: x[0])

if counter[0][1] > 1:
    print(0)  # 1との距離が0のものがあったらアウト
    exit()

# 距離が2離れているものは定義できない
now = counter[0][0]
for i in range(1, len(counter)):
    if counter[i][0] != (now+1):
        print(0)
        exit()
    now = counter[i][0]

# これですべての例外は弾けた
ans = 1
for i in range(len(counter)):
    ans *= kaizyo[counter[i][1]]
    if counter[i][1] == 1 and counter[i][0] != 0:
        ans *= (counter[i][0]-1)

# print(counter)
print(ans)

Submission status: Wrong Answer

Solution code:
def listConvert(baseList):
  maxNum = max(baseList)
  newList = [0] * (maxNum + 1)
  for a in baseList:
    newList[a] += 1
  return newList

n = int(input())
baseList = list(map(int, input().split()))
isZero = False

if baseList[0] != 0:
  print(0)
  isZero = True

newList = listConvert(baseList)
if newList[0] > 1:
  print(0)
  isZero = True
if newList.count(0) > 0:
  print(0)
  isZero = True

result = 0
if not isZero:
  result = 1
  preA = 1
  mod = 998244353
  for a in newList:
    result = (result * pow(preA, a)) % mod
    preA = a

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d.count(0) != 1:
        print(0)
    else:
        count = 1
        for i in d[1:]:
            count *= i % mod
        print(count % mod)


if __name__ == '__main__':
    main()