Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

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

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

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

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

for i in range(N):
    temp[i] = list.count(i)

temp2 = [0 for i in range(N)]
count = 0
for i in range(N):
    if temp[i] == 0:
        temp2[i] = 1
        if temp2[i-1] == 0:
            count += 1
if temp[0] == 0:
    count = 2

if count != 1:
    ans = 0
else:
    m = temp2.count(0)
    for i in range(1, m):
        ans = (ans * (temp[i-1] ** temp[i])) % 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
MOD = 998244353

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

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

mod = 998244353
from collections import Counter

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

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

  dic = {}
  for dd in d:
    if dd in dic:
      dic[dd] += 1
    else:
      dic[dd] = 1

  ans = 1
  t = sorted(dic.items(), key = lambda x: x[0])
  for i in range(1, len(t) - 1):
    x = (t[i][1] ** t[i+1][1]) % mod
    ans *= x
    ans %= mod
  print(ans % mod)
 

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
_,*D=map(int,open(0).read().split());a=1;M=[0]*-~max(D)
for d in D:M[d]+=1
for m,n in zip(M,M[1:]):a=a*m**n%998244353
print((M[0]<2)*a)

Submission status: Wrong Answer

Solution code:
def cnt_figure(ls):
    figure = 1
    figure_cnt = 0
    ls_len = len(ls)
    re_fg_ls = []
    for i in range(ls_len):
        if figure == ls[i]:
            figure_cnt+=1
        else:
            re_fg_ls.append(figure_cnt)
            figure+=1
            figure_cnt=1
    re_fg_ls.append(figure_cnt)
    re_fg_ls.append(0)
    return re_fg_ls

n = int(input())
d_list = list(map(int, input().split()))
#print(d_list)
total = 0
now_figure = 0
if d_list[0] != 0:
    print(0)
else:
    d_list.pop(0)
    d_list.sort()
    #print(d_list)
    figure_ls = cnt_figure(d_list)
    #print(figure_ls)
    figure_ls_len = len(figure_ls)
    before_cnt = 1
    i = 0
    total = 1
    while figure_ls[i] != 0:
         total = total *(before_cnt**figure_ls[i]) % 998244353
         #print(total,"total")
         before_cnt = figure_ls[i]
         i+=1
    print(total % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
a = sorted(d)
checkZero = False
if(d[0] != 0):
    checkZero = True
for i in range(1,len(d)):
    if(d[i] == 0):
        checkZero = True

if(checkZero):
    print(0)
else:
    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()))
import collections as col
E = col.Counter(D)
def tree(L):
    t = 1
    if L[0] != 1:
        return 0
    else:
        for i in range(1,len(L)):
            t = t * (L[i-1]**L[i])
        return t % 998244353
print(tree(E))

Submission status: Wrong Answer

Solution code:

N = int(input())

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

if D[0] != 0 or D.count(0) !=1:
    print("0")
    exit()

counted = []

for i in range(1,N):
    counted.append(D.count(i))

#print(counted)

#calc
result = 1
x = counted[0]
for i in range(1,len(counted)):
    y = counted[i]
    if y!= 0:
        result = result * pow(x,y)
        x = y
print(result)

Submission status: Wrong Answer

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

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])%998244353
if len(c) != c[-1][0]+1:
  key = 0
if key == 1:
  print(s)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
D = list(map(int,input().split()))

sort_D = sorted(D)
set_D = set(D)

sum = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
elif len(set_D)-1 == max(set_D):
  for i in range(len(set_D)):
    if i >= 1:
      sum *= D.count(i-1)**D.count(i)
  print(sum)
else:
  print(0)

Submission status: Wrong Answer

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

for i in range(1,n-1):
  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()

D_num = []
count = 1
for i in range(N):
    if i == N-1 or D[i] != D[i+1]:
        D_num.append([D[i],count])
        count = 1
    else:
        count += 1

D_max = D[N-1]

if len(D_num) != D_max+1:
    print(0)
else:
    result = 1
    for i in range(1,D_max+1):
        result = result * (D_num[i-1][1] ** D_num[i][1] % 998244353)
        result = result % 998244353

    print(result)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

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

mod = 998244353
from collections import Counter

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

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

  dic = {}
  for dd in d:
    if dd in dic:
      dic[dd] += 1
    else:
      dic[dd] = 1

  ans = 1
  t = sorted(dic.items(), key = lambda x: x[0])
  for i in range(1, len(t) - 1):
    x = (t[i][1] ** t[i+1][1]) % mod
    ans *= x
    ans %= mod
  print(ans % mod)
 

if __name__ == '__main__':
  main()

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

mod = 998244353
L = []
f = 0
num = 0
cnt = 0
D.sort()
for i in range(N):
    if D[i] == num:
        cnt += 1
    elif D[i] == num+1:
        L.append(cnt)
        cnt = 1
        num += 1
    else:
        f = -1
        break
        
L.append(cnt)
ans = 1
if f == 0:
    if D[0] != 0:
        ans = 0
    if N > 1:
        if D[1] != 1:
            ans = 0
    if ans > 0:
        for i in range(1, len(L)):
            ans *= L[i-1]**L[i]
            ans %= mod
else:
    ans = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
E=list(map(int, input().split()))
k=max(E)
D={}
for i in range(k+1):
    D[i]=0
for i in range(N):
    D[E[i]]+=1
    

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

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
dis = 98244353
 
if D[0] != 0:
  print(0)
  exit()
D.sort()
if D[1] == 0:
  print(0)
  exit()
ans = 1
c = 1
num = 1
for i in range(1,len(D)):
  if D[i] == D[i-1] and i != len(D)-1:
    c += 1
  else:
    ans = ans * num**c
    num = c
    c = 1
    if i == len(D)-1 and D[i] != D[i-1]:
       ans = ans * num**c

  #print(ans,num,c) 

print(ans%dis)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

N = int(input())
D_list = list(map(int, input().split()))
P = 998244353
n = 1
c = Counter(D_list)
if c[0] == 0:
    print(0)
else:
    pre = 1
    for i in range(1, max(D_list) + 1):
        if c[i] == 0:
            print(0)
            sys.exit()
        n = (n * ((pre ** c[i]) % P)) % P
        pre = c[i]
    print(n)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


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

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

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

        cnt = []
        before = 0
        for d in D:
            if d > before + 1:
                print(0)
                exit()
            else:
                if len(cnt) == d - 1:
                    cnt.append(1)
                else:
                    cnt[-1] += 1
                before = d

        ans = 1
        for i, v in enumerate(cnt):
            if i > 0:
                ans *= (cnt[i - 1]) ** v
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

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

mod=998244353
if D[0]!=0:
  print(0)
else:
  ans=1
  c=collections.Counter(D)
  for i in range(2,n):
    ans*=c[i-1]**c[i]
    if ans==0:
      print(ans)
      exit()
  print(ans%mod)

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
m=max(d)


for i in range(m):
    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())
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 a == 0:
      print(0)
      break
  print(a)

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 
    if L[0] != 1:
        print(0)
        return
    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:
MOD = 998244353 
N = int(input())
D = [int(x) for x in input().split()]
zero = 0 
for d in D:
    zero += (d == 0)
if (zero != 1):
    print(0)
    exit()
i = 0
maxD = max(D)
while(i in D):
    i += 1
if (maxD != i-1):
    print(0)
    exit()
lst = [0] * (N)
for d in D:
    lst[d] += 1
ans = 1
for i in range(N-1):
    ans *= lst[i] ** lst[i+1]
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

d_cnt = {}
d_max = max(ds)

d_cnt = { i: ds.count(i) for i in range(d_max + 1) }

cnt = 1
for i in range(1, d_max + 1):
    if (i - 1) not in d_cnt or i not in d_cnt:
        cnt = 0
        break

    cnt *= d_cnt[i - 1] ** d_cnt[i]

print(cnt % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0]*N
for D in Ds:
    counter[D] += 1
total = 0
cnt = 0
prenumi = 0
for i in range(N):
    if i == 0:
        if counter[i] == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = counter[i]
        if numi != 0:
            total = total * (prenumi ** numi)
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break

print(total % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

const = 998244353

m = max(d)

ans = 1

for i in range(m + 1):
    if d.count(i) == 0:
        ans = 0
        break
    else:
        if i == 0:
            ans = ans * d.count(0)
        else:
            new = d.count(i)
            old = d.count(i - 1)
            a = pow(old, new)
            ans = ans * a

print(ans % const)

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])%998244353)
	kotae=kotae%998244353
	print(int(kotae))

Submission status: Wrong Answer

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

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

d.sort()

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

i = 1
dis = 1
sep = [0] * (10 ** 5)
sep[0] = 1
ans = 1
while i < n:
    if d[i] != dis:
        print(0)
        exit()
    while i < n and d[i] == dis:
        sep[dis] += 1
        i += 1
    ans *= sep[dis-1] ** sep[dis]
    dis += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    if n<1: return 1
    if n-r<0: return 1
    if r< 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

sum = 1
num_pre = 0
for i in range(1,N):
    num_i = D.count(i)
    if num_i == 0:
        break
#    print "*** "                                                                                      
#    print num_i, num_pre                                                                              
    c = cmb(num_i + num_pre - 1, num_i)
    if c ==0:
        c= 1
    sum = sum*c
    num_pre = num_i

print sum

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

Submission status: Wrong Answer

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


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

    print('Yes')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if D[0]!=0:
    print(0)
else:
    count_list = [ np.where(D==x,1,0).sum() for x in range(1,D.max()+1)]
    
    if 0 in count_list:
        print(0)
        
    ans = 1
    for x in range(len(count_list)-1):
        ans = ans * (count_list[x]**count_list[x+1])
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = list(map(int, input().split(' ')))
ans = 1
m = max(set(ls))
d = {}
for l in ls:
    d[l] = d.get(l, 0) + 1
if ans != 0:
    for i in range(1, m+1):
        ans = (ans * (d.get(i-1, 0) ** d.get(i, 0))) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


N = int(input())
D = [int(d_) for d_ in input().split()]

D_list = list(set(D))
D_count = []
for d_ in D_list:
    D_count.append(D.count(d_))
if (D_list[-1] != len(D_list) - 1) | (D_count[0] != 1):
    print(0)
else:
    ans = 1
    D_count = np.array(D_count)
    D_ = D_count[:-1]**D_count[1:]
    print(D_.prod() % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

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)
    ans = ans % num

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
cs = Counter(D)
count = 0
ans = 1
prev = 1
for i in range(N + 1):
    n = cs[i]
    if n == 0:
        if count == N:
            print(ans)
        else:
            print(0)
        exit(0)
    else:
        count += n
        ans = (ans * (prev ** n)) % 998244353
        prev = n

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
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]) % mod
        else:
            print(0)
            exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D = groupby(sorted(D))
t = 998244353

ans = 1
pre = 0
cur = 0
for i, d in D:
    if i != cur:
        print(0)
        exit()
    else:
        cur += 1
    l = len(list(d))
    if i <= 1:
        pre = l
        continue
    ans = ans * (pre**l)
    pre = l

print(ans % t)

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:
  for i in range(D.count(0)):
    D.remove(0)
  print(np.prod(D))

Submission status: Wrong Answer

Solution code:
def cnt_figure(ls):
    figure = 1
    figure_cnt = 0
    ls_len = len(ls)
    re_fg_ls = []
    for i in range(ls_len):
        if figure == ls[i]:
            figure_cnt+=1
        else:
            re_fg_ls.append(figure_cnt)
            figure+=1
            figure_cnt=1
    re_fg_ls.append(figure_cnt)
    re_fg_ls.append(0)
    return re_fg_ls

n = int(input())
d_list = list(map(int, input().split()))
#print(d_list)
total = 0
now_figure = 0
if d_list[0] != 0:
    print(0)
else:
    d_list.pop(0)
    d_list.sort()
    #print(d_list)
    figure_ls = cnt_figure(d_list)
    #print(figure_ls)
    figure_ls_len = len(figure_ls)
    before_cnt = 1
    i = 0
    total = 1
    while figure_ls[i] != 0:
         total = total *(before_cnt**figure_ls[i])
         #print(total,"total")
         before_cnt = figure_ls[i]
         i+=1
    print(total)

Submission status: Wrong Answer

Solution code:
BIGMOD = 998244353

def modPow(x,n):
    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

def modFact(N):
    fact = []
    fact.append(1) #0! = 1
    for i in range(1,N+1):
        a = fact[i-1]*i % BIGMOD
        fact.append(a)
    return fact

def modInvFact(fact):
    invFact = []
    for i in range(1,N+2):
        a = modPow(fact[i-1],BIGMOD-2)
        invFact.append(a)
    return invFact

def modPlus(a,b):
    return (a + b) % BIGMOD

def modMinus(a,b):
    if a-b >= 0:
        return (a - b) % BIGMOD
    else:
        return (a - b + BIGMOD)
    
def modMulti(a,b):
    return a * b % BIGMOD

# fact(n),invFact(r),invFact(n-r)
def nCr(fact,invFact,n,r):
    return (fact[n] * invFact[r] * invFact[n-r] ) %BIGMOD

def nPr(fact,invFact,n,r):
    return(fact[n] * invFact[r])%BIGMOD

def fact(num):
    ans = 1
    for i in range(1,num+1):
        ans = ans*i%BIGMOD
    return ans

import collections

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

S = list(set(D))
S.sort()
if S[0]==0:
    S.pop(0)
ans = 1
before = 0
before_i = 0
c = collections.Counter(D)
for i in S:
    if i == 1:
        before = c[i]
        before_i = i
        continue
    ans = ans*modPow(before,c[i])%BIGMOD
    before = c[i]
    if i - before_i!=1:
        ans = 0
    before_i = i
if D[0] >0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
dis = 98244353
 
if D[0] != 0:
  print(0)
  exit()
D.sort()
if D[1] == 0:
  print(0)
  exit()
ans = 1
c = 1
num = 1
for i in range(1,len(D)):
  if D[i] == D[i-1] and i != len(D)-1:
    c += 1
  else:
    ans = ans * num**c
    num = c
    c = 1
    if i == len(D)-1:
       ans = ans * num**c

  #print(ans,num,c)

print(ans%dis)

Submission status: Wrong Answer

Solution code:

import sys
n = int(input())
array = list(map(int, input().split()))
dic = {0:0}
for i in range(n):
    key = array[i]
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
j = 1
count = 1
while j in dic:
    if j-1 in dic:
        count *= dic[j-1]**dic[j]%998244353
        count %= 998244353
        j += 1
    else:
        print(0)
        exit()
print(count)

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
D=list(map(int,input().split()))
D.sort()
m=max(D)
counter=[]
for i in range(m+1):
    counter.append(bisect.bisect_right(D,i)-bisect.bisect_left(D,i))
ans=1
for i in range(1,m+1):
    ans*=counter[i-1]**counter[i]
print(ans%998244353)

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]] % mod)
    if counter[i][1] == 1 and counter[i][0] != 0:
        ans *= ((counter[i][0]-1) % mod)

# print(counter)
print(ans % mod)

Submission status: Wrong Answer

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

d.sort()
ans=True
now=0
for i in d:
    if(i>(now+1)):
        ans=False
    elif(i==now+1):
        now+=1

if(ans):
    print(now)
else:
    print("0")

Submission status: Wrong Answer

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

ans = 1
ans_li = [0 for i in range(n)]

li.sort()
count = 0
for i in range(n):
    ans_li[li[i]] += 1

if not ans_li[0] == 1:
    print(0)
    exit()
else:
    for i in range(1,n-1):
        ans *= ans_li[i] ** ans_li[i+1]

for i in range(n-1):
    if ans_li[i] == 0 and (not ans_li[i+1] == 0):
        print(0)

print(ans % 998244353)

Submission status: Wrong Answer

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

D.sort()

D_num = []
count = 1
for i in range(N):
    if i == N-1 or D[i] != D[i+1]:
        D_num.append([D[i],count])
        count = 1
    else:
        count += 1

D_max = D[N-1]

if len(D_num) != D_max+1:
    print(0)
else:
    result = 1
    for i in range(1,D_max+1):
        result = result * D_num[i-1][1] ** D_num[i][1]
        result = result % 998244353

    print(result)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
D = list(map(int, input().strip().split(" ")))
d = list(set(D))

if min(d) > 0 or max(d) >= len(d):
    print(0)
    exit()

c = 1
x = [0] * len(d)
for i in D:
    x[i] += 1
if x[0] != 1:
    print(0)
    exit()
for i in range(1,len(d)):
    c *= x[i-1]**x[i]
    c = c % 998244353

print(c % 998244353)

Submission status: Wrong Answer

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

D.sort(reverse=True)
maxD = D[0]

result = 1

for i in range(1,maxD):
  result *= D.count(i) ** D.count(i+1)

if D.count(0) == 1:
  print(result)
else:
  print(0)

Submission status: Wrong Answer

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

d_max=max(d)
ans=1
flag=True

if d[0]!=0:
    print(0)
elif d.count(0)>1:
    print(0)
elif d_max==1:
    print(d.count(1))
else:
    for i in range(2, d_max+1):
        if d.count(i-1)==0:
            flag=False
            break
        else:
            ans*=(d.count(i-1)**d.count(i))%998244353
    print(ans%998244353 if flag else 0)

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
Ds=list(map(int,input().split()))

Ans=[0]*(max(Ds)+1)

Ans[0]=1

for i in range(1, max(Ds)+1):
    Ans[i]=Ds.count(i-1)**Ds.count(i)

print(np.prod(Ans))

Submission status: Wrong Answer

Solution code:
M = 998244353

N = int(input())
d_list = list(map(int, input().split()))
d_list.sort()

def fact(n):
	f = 1
	for i in range(2, n + 1):
		f = (f * i) % M
	return f

def check():
	d = d_list.pop(0)
	if d != 0:
		print(0)
		return
	else:
		if len(d_list) == 0:
			print(1)
			return
		elif d_list[0] == 0:
			print(0)
			return
		else:
			d_counts = [1]
			prev_d = 0
			for d in d_list:
				if prev_d == d:
					d_counts[prev_d] += 1
				elif prev_d + 1 == d:
					d_counts.append(1)
					prev_d = d
				else:
					print(0)
					return
			count = 1
			prev_d = d_counts.pop(0)
			for d in d_counts:
				count = (count * pow(prev_d, d, M)) % M
				prev_d = d
			print(count)

check()

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)

if len(dd) != d[-1]+1:
    print(0)
    sys.exit()

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

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

mod = 998244353

c = collections.Counter(d)

if set(d)=={0}:
	print(1)
	sys.exit()

ans=1
a=set()
for i,g in c.items():
	if i!=0:
		ans = ans*(i**g)
	a.add(i)

if a!=set([i for i in range(max(d)+1)]):
	print(0)
	sys.exit()

print(ans%mod)

Submission status: Wrong Answer

Solution code:
def modpow(a, n, mod):
    bi = format(n, 'b')
    res = 1
    for i in range(len(bi)):
        res = (res * res) % mod
        if bi[i] == '1':
            res = (res * a) % mod
    return res

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

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

ans = 1
for i in range(len(L)-1):
    ans *= modpow(L[i], L[i+1], mod)
    
print(ans % mod)

Submission status: Wrong Answer

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

mod=998244353

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

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

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

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

# print(counter)
print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(x) for x in input().split()]
D_counter = Counter(D)
ans = 1
for d in D_counter:
    if d - 1 in D_counter:
        ans *= (D_counter[d - 1] ** D_counter[d])
        ans = ans % 998244353
    else:
        if not d == 0:
            ans = 0
            break
print(ans)

Submission status: Wrong Answer

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

d={}
for i in D:
    d[i]=d.get(i,0)+1

s = 0
for l in range(1, max(D)):
    if l == 1: s = 1
    if l not in d or (l+1) not in d:
        s=0
        break
    for i in range(d[l+1]):
        s *= d[l]

print(s)