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

mod=998244353
c=collections.Counter(D)

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

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()
            
    total = 1
    for i in range(1, maximum):
        base = bisect.bisect_right(d, i) - bisect.bisect_left(d, i)
        exp = bisect.bisect_right(d, i+1) - bisect.bisect_left(d, i+1)
        total *= base ** exp
    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()))

L=sorted(set(D))
d={}
c=0
F = (D[0]==0) and (L[0]==0)
if F:
    for i in L:
        if c!=i:
            if (c+1)==i:
                c+=1
            else:
                F=False
                break
if F:              
    for i in D:
        d[i]=d.get(i,0)+1

s = 0
if F:
    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)

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:
    if b_count == 1:
      Ans = Ans * n_count
      Ans = Ans % 998244353
    else:
      Ans = Ans * (b_count ** n_count)
      Ans = Ans % 998244353
  print(Ans)

Submission status: Wrong Answer

Solution code:
from math import factorial


N = int(input())
D = list(map(int, input().split()))
maxD = max(D)
rng = range(0, maxD + 1)

cnt = []
for i in rng:
    cnt.append(D.count(i))

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

ans = 1
for idx, val in enumerate(cnt):
    if idx == len(cnt) - 1:
        break
    n = val
    r = cnt[idx + 1]
    ans *= n ** r

print(int(ans))

Submission status: Wrong Answer

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

import collections
c=collections.Counter(D)
ans=1

if D[0]!=0:
  print(0)
else:
  for i in range(2,N):
    ans*=(c[i-1]**c[i])
  print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
import sys
N  = int(input())
Ds = np.array(list(map(int, input().split(' '))))
if Ds[0] != 0:
    print(0)
    sys.exit()
if np.any(Ds[1:] == 0):
    print(0)
    sys.exit()

uniq = np.unique(Ds)
uniq.sort()

if not np.all(uniq == np.arange(uniq.min(), uniq.max() + 1)):
    print(0)
    sys.exit()
C = collections.Counter(Ds)
counts = 1
for i in range(1, uniq.max() + 1):
    counts *= C[i-1] ** C[i]
print(counts // 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

def solve(n, d):
    if d[0] != 0:
        print(0)
        return

    count = {}
    pre = 0
    for i, d_i in enumerate(sorted(d)):
        if d_i != pre and d_i + 1 == pre:
            print(0)
            return

        if d_i not in count:
            count[d_i] = 0
        count[d_i] += 1

    ans = 1
    pre = 1
    for i, c in count.items():
        if i == 0:
            continue

        ans *= (nCr(pre, 1) ** c)
        ans = ans % 998244353
        pre = c

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    d = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, d)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
import bisect
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

point = 0

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

k = bisect.bisect(li,1)

li = li[k:]

lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))

point = 1
for i in range(len(lin)):
    point*= lin[i][0]**lin[i][1]

print(point%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
coun = [0]*N
ans = 1
for i in range(N):
  coun[i]=D.count(i)
for i in range(1,N):
  ans = ans*pow(coun[i-1],coun[i])
print(int(ans%998244353))

Submission status: Wrong Answer

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

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

set_D = set(D)
c = collections.Counter(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 *= c[i-1]**c[i]
  print(sum)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]==1:
    ans = 1
    for i in range(len(dict(cnt))-1):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD

    print(ans%MOD)
except KeyError:
  print(0)

Submission status: Wrong Answer

Solution code:
import sys
import collections
def solve():
    sys.setrecursionlimit(100000)
    mod = 998244353

    N = int(input())
    D = list(map(int, input().split()))
    cnter = collections.Counter(D)
    cnter = sorted(cnter.items())

    ans = 1
    if cnter[0][0] != 0 or cnter[0][1] != 1 : 
        ans = 0
    else:
        for i in range(2, len(cnter)):
            if cnter[i][0] != i:
                ans = 0
                break

            else:
                ans *= cnter[i-1][1] ** cnter[i][1]
    
    print(ans%mod)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n = I()
    print(n // 2 - 1 if n % 2 == 0 else n // 2)
    return


# B
def B():
    n = I()
    d = LI()
    if d[0] != 0:
        print(0)
        return
    d.sort()
    if d[1] == 0:
        print(0)
        return
    cnt = []
    prenum = 1
    for i in range(1, max(d) + 1):
        num = bisect.bisect_right(d, i)
        if num - prenum == 0:
            print(0)
            return
        else:
            cnt.append(num - prenum)
            prenum = num
    ans = 1
    for i in range(1, max(d)):
        ans *= cnt[i - 1] ** cnt[i]
    print(ans)
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    B()
    return


# Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
import bisect
N=int(input())
D=list(map(int,input().split()))
if D[0]==0:
    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(m+1):
        if counter[i-1]==0:
            counter[i-1]=1
        ans*=counter[i-1]**counter[i]
    print(ans%998244353)
else:
    print(0)

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):
    prev = 1
    s = 1
    visited = 1
    for i in range(1, 10 ** 5):
        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:
N = int(input())
s = list(map(int, input().split()))
item = 0
sum = 0
node = 0
count = 0
before = 0

for i in range(N):
    count = s.count(i)
    node += count
    if i == 0:
        if count != 1:
            break
        else:
            before = 1
            sum = 1
    else:
        if count == 0:
            break
        else:
            sum = sum * (before ** count)
            before = count

if node != len(s):
    print("0")
else:
    print(sum%998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    v = list(c.values())
    for i in range(1, len(v)):
        ans *= (v[i-1]**v[i]) % MOD
    print(ans % MOD)

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

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def solve(N,D):
    if D[0]:
        return 0

    try:
        idx = D[1::].index(0)
        for d in D[idx+1::]:
            if d:
                return 0
    except:
        pass
    
    nums = Counter(D)
    nums = sorted(nums.items())
    #print(nums)
    ans = 1
    for i in range(len(nums)-1):
        ans *= nums[i][1]**nums[i+1][1]
        ans %= 998244353
    return ans

def main():
    N = int(input())
    D = list(map(int, input().split()))
    
    print(solve(N,D))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
mx=d[-1]
count=[0]*(mx+1)
MOD=998244353
for i in range(n):
    count[d[i]]+=1
c=1
#print(d,count)
if count[0]!=1:
    print(0)
    sys.exit()
for i in range(1,mx+1):
    c*=pow(count[i-1],count[i],MOD)
    c%=MOD
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
deep,a,b,c = 0,1,0,1
for i in range(n):
  if s[i] == deep:
    b += 1
  elif i == n:
    c *= a ** b
  elif s[i] == deep + 1:
    c *= a ** b
    a = b
    b = 1
    deep += 1
  else:
    c = 0
    break
    
  if i == n-1:
    if s[i] == deep:
      c *= a ** b
    elif s[i] == deep + 1:
      c *= a ** b
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

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

if A[0] != 0:
    print(0)
else:
    L = [0]*(n+1)
    for i in range(n):
        L[A[i]] += 1

    if L[0]!=1:
        print(0)
    else:
        ans = 1
        nxt = 1
        for i in range(1,n):
            if L[i]>0:
                for k in range(L[i]):
                    ans *= L[i-1]
                    ans %= mod
            else:
                nxt = i
                break
        for j in range(nxt,n+1):
            if L[j] != 0:
                print(0)
                break
        else:
            print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def answerA():
    input = sys.stdin.readline
    N = int(input())

    print((N-1) // 2)



import numpy as np

def answer():
    input = sys.stdin.readline
    N = int(input())
    distances = list(map(int, input().split()))

    maximum = max(distances)
    counts = []

    for d in range(maximum + 1):
        counts.append(distances.count(d))

    result = 1
    mod = 998244353

    if 0 in counts:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        counts_prev = np.array(counts[:-1])
        counts_next = np.array(counts[1:])

        matrix = np.power(counts_prev, counts_next)
        result = matrix.prod() % mod

    print(result)


if __name__ == '__main__':
    answer()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
d.sort()
ans = 1
if d[0] != 0:
    print(0)
else:
    zero_count = d.count(0)
    for i in range(zero_count):
        d.remove(0)
    for j in range(len(d)):
        ans *= d[j]
    print(ans)

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)
    ans %= mod
    
print(ans)

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

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

d.sort()

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

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

d.sort()
e = collections.Counter(d)
e = e.most_common()
e =list(e)
e.sort()

if d.count(0)!=1:
    print(0)
    exit()


for i in range(1,len(e)):
    if e[i][0]-e[i-1][0]!=1:
        print(0)
        exit()
    
    else:
        ans*=(e[i-1][1])**e[i][1]
        ans=ans%mod
print(ans)

Submission status: Wrong Answer

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

MOD = 998244353

occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
for i in range(1, N+5):
    if occ[i] == 0:
        for j in range(i, N+5):
            if occ[j] != 0:
                print(0)
                quit()
        break
    if occ[i] != 0 and occ[i - 1] == 0:
        print(0)
        quit()
    for j in range(occ[i]):
        cur = (cur * occ[i - 1]) % MOD

print(cur % MOD)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
temp = 0
pre = 1
mod = 998244353
c = 1

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

if a == 0:
    D = sorted(D)
    for i, d in enumerate(D):
        if i == 0:
            continue
        if d == 0:
            print(0)
            a = 1
            break
        if temp != d:
            ans *= pre ** c

            temp = d
            pre = c
            c = 1
        else:
            c += 1

        if i == N-1:
            ans *= pre ** c
    if a == 0:
        print(ans%mod)

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 D[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

N=int(input())
D=list(map(int,input().split()))
if D[0]==0:
  A=collections.Counter(D)
  c=1
  for i in range(max(D)-1):
    c*=A[i+1]**A[i+2]
  ans=c%998244353  
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    depth = max(d)
    counts = []
    for i in range(depth + 1):
        counts.append(d.count(i))
    pows = [counts[0]]
    for i in range(1, depth + 1):
        c = counts[i]
        c_past1 = counts[i - 1]
        pows.append(mod_pow(a=c_past1, n=c, mod=MOD))
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if d[0] != 0:
  print(0)
else:
  M = max(d) + 1
  num = [0] * M
  ans = 1
  for i in range(M):
    num[i] = d.count(i)
  for i in range(M-2):
    ans = ans * np.power(num[i+1], num[i+2]) % 998244353
  print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0:
  print(0)
  exit()

prev = 0
for i in range (N):
  if i == 0:
    prev = 1
    if D[0] != 0 or D.count(i) > 1:
      print(0)
      exit()
  else:
    count = D.count(i)
    ans = ans * ((prev**count) %998244353 ) 
    prev = count
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
D = [int(x) for x in input().split()]
D_counter = Counter(D)
ans = 1

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

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

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

if min(Ds)!=0 or Ds.count(0)!=1:
    print(0)
else:
    Ans=[0]*(max(Ds)+1)
    Ans[0]=1
    for i in range(1, max(Ds)+1):
        Ans[i]=Ans[i-1]*(Ds.count(i-1)**Ds.count(i))
    print(Ans[max(Ds)])

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ansflag = 0
ans = 1
for i in range(len(D_)):
    temp = D_[i]
    if temp == 0:
        ansflag = 1
        break
    else:
        if  i > 0:
            ans *= D_[i-1] ** D_[i]
            ans % 998244353

if ansflag:
    print(0)
else:
    print(ans)

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 = ((count % mod) * (i % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
E = [abs(i-D[0]) for i in D[1:]]
d = dict(Counter(sorted(E)))
sum_=1
temp=1
i_temp = 0
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:
temp = list(map(int, input().split()))
N = temp[0]
Ds = temp[1:]

counter = list(map( (lambda x: 0), range(N) ))

for distance in Ds:
    counter[ distance ] += 1   

if N == 1:
    if counter[0] == 1:
        result = 1
    else:
        result = 0
else:
    if counter[0] != 1 :
        result = 0
    else:
        result = 1

if N > 2:
    for distance in range(2,N):
        temp = pow( counter[distance-1], counter[distance] ) % 998244353
        result = (result * temp) % 998244353
         
print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
c=[0]*n
ans=0
for i in range(0,n):
  c[d[i]]+=1

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(2,n):
    if c[j]==0 and j<=n-2:
      if c[j+1]!=0:
        print(0)
        break
      else:
        ans+=0
    elif c[j]==0 and j==n-1:
      ans+=0
    else: 
      ans*=c[j]**c[j-1]
      
  print(int(ans%998244353))

Submission status: Wrong Answer

Solution code:
# 2019/11/9

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

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

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


def cmb(n,r,mod=10**9+7):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i%mod)
    ret=fac[n]*pow(fac[r]*fac[n-r]%mod,mod-2,mod)%mod
    return ret


ans=1
pre=res.get(1,-1)
if pre==-1:
    print(0)
    exit()

cnt=0
for i in range(2,len(res)):
    tmp=res.get(i,-1)
    if tmp==-1:
        print(0)
        exit()
    j=1
    while j<tmp:
        cnt+=cmb(tmp,j)
        j+=1
    cnt+=pre
    ans*=cnt
    cnt=0
    pre=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
li = sorted(li)
count = 1
a = 0
b = 1
if not (1 in li and 0 in li):
    count = 0
else:
    del li[0]
    for i in range(1,len(li)):
        flag = True
        a = 0
        while flag:
            if li == []:
                count *= b ** a
                b = a
                flag = False
            elif i == li[0]:
                a += 1
                del li[0]
            else:
                count *= b ** a
                b = a
                flag = False
        
print(count % 998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

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

print(ans)

Submission status: Wrong Answer

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

ans = 1
if d[0] != 0 and sum(d) < n - 2 and sum(d) > (n * (n + 1) // 2) + 1:
    print(0)
else:
    l = [0] * (max(d) + 1)
    for i in range(n):
        l[d[i]] += 1

    if l[0] != 1:
        print(0)
    else:
        for j in range(1, len(l)):
            if l[j] == 0:
                ans = 0
                break
            else:
                x = l[j - 1] ** l[j] % mod
                ans *= x
                ans %= mod
        print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 1

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ans = 1
if D[0] > 1: print(0)
else:
    for i in range(N):
        ans = (ans * D[i] ** D[i+1]) % 998244353
    
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
D.sort()

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

ans = 1
mod = 998244353
b = 1

temp = 1
for i in range(1, N):
    if D[i] == 0:
        print(0)
        exit()
    if D[i] - D[i - 1] > 1:
        print(0)
        exit()
    if D[i] != D[i - 1]:
        b = temp
        temp = 1
    else:
        temp += 1
    ans *= b
    ans %= mod

print(ans % mod)

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_counts = []
	prev_d = -1
	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_c = d_counts.pop(0)
	if prev_c != 1:
		print(0)
	else:
		for c in d_counts:
			count = (count * pow(prev_c, c, M)) % M
			prev_c = c
		print(count)

check()

Submission status: Wrong Answer

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

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

count_dict = sorted(Counter(D).items(), key=lambda x:x[0])
count_list = list(dict(count_dict).values())

if len(count_list) == max(D) + 1:
    ans = 1
    for i in range(len(count_list)):
        if i == 0:
            if D[0] == 0:
                pass
            else:
                ans = 0
                break
        else:
            ans *= power_func(count_list[i - 1], count_list[i], p)
else:
    ans = 0

ans %= p
print(ans)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D.sort()
count = Counter(D)
ans = 1
for i in range(1, D[-1] + 1):
    if i not in count:
        print(0)
        exit()
    ans *= count[i-1] ** count[i]
print(ans % 998244353)

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]
if D[0]==1:
    print(ans%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    n = I()
    print(n // 2 - 1 if n % 2 == 0 else n // 2)
    return


# B
def B():
    n = I()
    d = LI()
    if d[0] !=0:
        print(0)
        return
    d.sort()
    cnt=[]
    prenum=1
    for i in range(1, max(d)+1):
        num=bisect.bisect_right(d, i)
        if num-prenum == 0:
            print(0)
            return
        else:
            cnt.append(num-prenum)
            prenum = num
    ans = 1
    for i in range(1,max(d)):
        ans*=cnt[i-1]**cnt[i]
    print(ans)
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    B()
    return


# Solve
if __name__ == "__main__":
    B()

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)
        c = tmp**cnt[i]
        ans *= c
        tmp = cnt[i]
        ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def count_tree(d):
    n = max(int(i) for i in d.keys())
    cnt = 1
    if d["0"] != 1:
        return 0
    for i in range(1, n):
        if d[str(i + 1)] > 0 and d[str(i)] < 1:
            return 0
        else:
            cnt *= d[str(i)] ** d[str(i + 1)]
    return cnt

input()
print(count_tree(Counter(input().split())))