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 numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline

mod=998244353

def main():
    n,*a=map(int,open(0).read().split())
    ans=1
    a=Counter(a)
    for i in range(min(a),max(a)):
        if a[i]==0 or a[i+1]==0:
            print(0)
            exit()
#        print(pow(a[i],a[i+1],mod),a[i],a[i+1])
        ans*=pow(a[i],a[i+1],mod)%mod
    print(ans%mod)

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
dic = {}
if d[0]:
    print(0)
else:
    for di in d:
        if di not in dic:
            dic[di] = 0
        dic[di] += 1
    dists = list(dic.keys())
    dists.sort()
    ans = 1
    l = [dic[dist] for dist in dists]
    if l[0] != 1:
        print(0)
    else:
        for l1, l2 in zip(l, l[1:]):
            ans = ans * (l1 ** l2) % mod
        print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int, input().split()))
D_C = collections.Counter(D)
D_C = D_C.items()
D_C = sorted(D_C)

#print(D_C)
N = len(D_C)
MOD = 998244353
ans = 1

if (D[0] != 0) or (D_C[0][1] != 1):
  ans = 0
  print(ans % MOD)
  quit()
  
fi = 0
for i in range(N-1):
  ans = ans * (D_C[i][1] ** D_C[i + 1][1])
  if D_C[i][1] == 0:
    fi = 1
  if (fi == 1) and (D_C[i][1] != 0):
    ans = 0
    print(ans)
    quit()
    
if (fi == 1) and (D_C[N-1][1] != 0):
  ans = 0
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter

mod = 998244353

def power_func(a,n,mod):
    bi=str(format(n,"b"))#2進表現に
    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()))

A = Counter(D)
B = sorted(A.items())

ans = 1
for i, (k, num) in enumerate(B):
    if i == 0:
        if k != 0 or num != 1:
            ans = 0
            break
        pre = 0
        continue
    if k != pre + 1:
        ans = 0
        break
    if k == 1:
        pre = 1
        p = num
        continue
    ans = ans * power_func(p, num, mod) % mod
    p = num
    pre = k
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d_array = list(map(int, input().split()))
if d_array[0] != 0:
    print(0)
else:
    count = [0 for _ in range(n)]
    count[0]=1
    for d in d_array[1:]:
        count[d] += 1
    i = 1
    node = 1
    ans = 1
    while node < n and i < n:
        ans *= count[i-1]**count[i]
        ans %= 998244353
        node += count[i]
        i += 1
    print(ans)

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

prev = 1
if 0 in m:
    s = 1
    for i in range(n ** 5):
        if not i in m:
            break
        v = m[i]

        s *= (prev ** v)
        prev = v
else:
    s = 0

print(s % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
D = [int(i) for i in input().split()]
if D[0] != 0:
    print(0)
    sys.exit()
D.sort()
if D[1] == 0:
    print(0)
    sys.exit()
a = Counter(D)
ans = 1
mod = 998244353
for i, (x, y) in enumerate(a.items()):
    if i != 0:
        ans *= x**y
        ans = ans % mod
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 :
  D_dict  = collections.Counter(D)
  result = 1
  for i in range(1, len(D_dict)) :
    if D_dict[i] == 0 :
      print(0)
      exit()
    else :
      result *= D_dict[i-1]**D_dict[i]
      result = result % mod

  print(result)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
m = max(D)
c = collections.Counter(D)

if 0 not in c.keys() or (c[0] != 1 and D[0] != 0):
    print(0)
    exit()

temp = 1
for i in range(1, m+1):
    if i not in c.keys():
        print(0)
        exit()
    ans *= temp**c[i]
    temp = c[i]

print(ans % 998244353)

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)

Submission status: Wrong Answer

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

# print(Ds)

from collections import defaultdict
d = defaultdict(int)

d_max = Ds[-1]
for D in Ds:
    d[D] += 1

ans = 1

for i in range(1,d_max+1):
    ans *= pow(d[i-1],d[i],mod)%mod

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
D = list(map(int,input().split()))
ans = 1
for i in range(1,N):
    ans *= D[i]
if D[0] != 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
mod = 998244353
ans = 1
flag = 0

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

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

import collections
d_count = collections.Counter(d)

for i in range(n):
     ans = ans * (d_count[i] ** d_count[i+1]) % mod
     
     if i > 0 and d_count[i] == 0 and d_count[i+1] != 0:
         print(0)
         sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

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

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

for i in range(n):
    tmp = d.count(i)
    if tmp != 0:
        c.append(tmp)
    else:
        break

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

print(ans)

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
for i in range(1,len(d)):
    c *= x[i-1]**x[i]
    c = c % 998244353

print(c)

Submission status: Wrong Answer

Solution code:
import sys

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

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

ans = 1
for d in D:
    if d == 0:
        continue

    elif d != 1:
        ans *= d

print(ans)

Submission status: Wrong Answer

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

# 存在しないパターン
def judge():
    if sum(D) < N-1:
        return False
    else:
        tmpd = 0
        for d in D:
            if abs(d - tmpd) > 1:
                return False
            tmpd = d
    
    return True

if not judge():
    print(0)
else:
    c = Counter(D)
    ret = 1
    cnt = 0
    for item in sorted(c.keys()):
        if item > 0:
            ret *= cnt ** c[item] % MOD
        cnt = c[item]
    print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    if arr[0] != 0:
        print(0)
        return
    
    mod = 998244353
    dist = {}
    arr1 = []
    for i in arr:
        if i not in dist.keys():
            dist[i] = 1
            arr1.append(i)
        else:
            dist[i] += 1

    if dist[0] > 1:
        print(0)
        return

    arr1.sort()

    #print(dist)
    ways = 1
    for i in range(1,len(arr1)):
        if arr1[i] - arr1[i-1] != 1:
            print(0)
            return
        prev = (ways*dist[arr1[i-1]])%mod
        curr = dist[arr1[i]]
        ways = pow(prev,curr,mod)
        #print(ways)

    print(ways)
         

main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


m = I()
D = LI()
cnt = Counter(D)
ret = 1
for i in range(max(D) + 1):
    val = cnt[i]
    if not val:
        print(0)
        break
    else:
        if i == 0:
            continue
        elif i == 1:
            pre = val
        else:
            ret = pre ** val * ret % mod
            pre = val
else:
    print(ret % mod)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = input().split()
D = np.array(D).astype(int)
D = np.sort(D)

max_depth = np.max(D)
min_depth = np.min(D)
if min_depth > 0:
  print(0)
elif (np.diff(D) > 1).sum() > 0:
  print(0)
else:
  out = 1
  last = list(D).count(1) #(D == 1).sum()
  for i in np.arange(2, max_depth+1):
    now = list(D).count(i)
    #now = (D == i).sum()
    out *= np.power(last, now)
    last = now
  print(out)

Submission status: Wrong Answer

Solution code:
from collections import Counter

B = int(input())
Dlist = list(map(int, input().split()))

A = 998244353

D_max = max(Dlist)
cnt = [0] * (D_max + 1)

dic = Counter(Dlist)
for k, v in dic.items():
    cnt[k] = v

ans = cnt[0]

if ans != 1:
    print(0)

else:
    for i in range(D_max):
        ans = ans * (cnt[i] ** cnt[i+1])
        ans = ans % A

    print(ans)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    mod = 998244353

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

    if d[0] > 0:
        print('0')
        exit()

    tmp = 1
    ans = 1
    for i in range(1, max(d)+1):
        count = d.count(i)
        if count == 0:
            print('0')
            exit() 
        ans *= tmp ** count
        tmp = count

    print(ans)

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
D = read_ints()

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


# 飛んだらアウト
# 個数を数えてどうにかする

from collections import Counter
dic = Counter(D)
ans = 1
if dic[0] != 1:
    print(0)
    exit()
# print(dic)
for i in range(max(D)):
    # もし連続してなかったらだめ
    try:
        ans *= dic[i]**dic[i + 1]
    except:
        print(0)
        exit

print(ans)

Submission status: Wrong Answer

Solution code:
CONST = 998244353
n = int(input())
d = list(map(int, input().split()))
l = [0 for i in range(n)]
max_d = max(d)
for i in d:
  l[i] += 1
ans = 1
cnt = 0
prev = 1
if d[0] != 0:
  print(0)
elif l[0] != 1:
  print(0)
else:
  for i in range(max_d+1):
    cnt = l[i]
    ans *= prev**cnt%CONST
    prev = cnt
  print(ans)

Submission status: Wrong Answer

Solution code:
mod=998244353

N=int(input())
L=[0 for i in range(N)]
D=list(map(int,input().split()))
#print(D)
for i in range(N):
    L[D[i]]+=1
#print(L)

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

ans=1
cnt=1
for i in range(1,N):
    ans*=L[i-1]
    ans%=mod
    ans=pow(ans,L[i],mod)
    
    cnt+=L[i]
    #print(ans,cnt)
    if cnt==N:
        break
print(ans)

Submission status: Wrong Answer

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

X = 998244353

l_max = max(D)

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)):
    ans = ans * (L[i-1] ** L[i])

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
D=list(map(int, input().split()))
if D[0]!=0:
    ans=0
else:
    E = collections.Counter(D)
    ans=1
    for i in range(1,len(E)):
        ans*=E[i-1]**E[i]
print(ans)

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)
else:
    lst = [0] * (N)
    for d in D:
        lst[d] += 1
    first0 = False
    for i in range(N):
        if (lst[i] != 0 and first0):
            print(0)
            exit()
        elif (lst[i] ==0):
            first0 = True
    ans = 1
    for i in range(N-1):
        ans *= lst[i] ** lst[i+1]
        ans %= MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys


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

    print((N-1) // 2)


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

    if 0 in counts:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        for i, count in enumerate(counts):
            result *= counts[i-1]**count

    print(result)


if __name__ == '__main__':
    answer()

Submission status: Wrong Answer

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

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

ans = 1
num = 0
num_before = 1
now = 1
for i in d[1:]:
    if now == i:
        num += 1
    elif i > now+1:
        print(0)
        exit()
    else:
        ans = (ans * num_before**num) % 998244353
        num_before = num
        num = 1
        now = i

ans = (ans * num_before**num) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:

N=int(input())
D=list(map(int,input().split()))
m=max(D)
counter=[]
for i in range(m+1):
    counter.append(D.count(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:
N = int(input())
A = list(map(int,input().split()))
D = [1 for _ in range(max(A)+1)]
for i in range(max(A)+1):
    D[i] = A.count(i)

ans = 1
if A[0] > 0:
    print(0)
else:
    for i in range(2,len(D)):
        ans *= D[i-1]**D[i]
    print(ans)

Submission status: Wrong Answer

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

if c[0] == 1:
    ans = 1
    for i in range(1, mx+1):
        if i not in c:
            ans = 0
            break
        else:
            ans *= c[i-1] ** c[i] % MOD
            ans %= MOD
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from collections import Counter


def main():
    n = int(input().strip())
    d = list(map(int, input().strip().split()))
    e = sorted(list(set(d)))
    for i, v in enumerate(e):
        if i != v:
            print(0)
            return
    v = dict(Counter(d))
    i = 0
    ans = 1
    while True:
        if i in v:
            if i == 0:
                i += 1
                continue
            ans *= v[i-1] ** v[i]
            ans %= 998244353
        else:
            break
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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





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

k=max(D)


ans=1
past=1
for i in range(1,k+1):
    n=D.count(i)
    ans*=past**n
    past=n

print(ans)

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
    for i in range(n):
        L[A[i]] += 1

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

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
m = max(D)
c = collections.Counter(D)

if 0 not in c.keys() or D[0] != 0:
    print(0)
    exit()

temp = 1
for i in range(1, m+1):
    if i not in c.keys():
        print(0)
        exit()
    ans *= temp**c[i]
    temp = c[i]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
ls=[int(s) for s in input().split()]
ls.sort()
k=max(ls)
ls2=[0 for i in range(k+1)]
for e in ls:
  ls2[e]+=1
if ls2[0]!=1:
  print(0)
else:
  ans=1
  for i in range(1,k):
    for j in range(ls2[i+1]):
      ans=(ans*ls2[i])%998244353
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys

pre_strk = 1
now_strk = 1
ans = 1
n = int(input())
d_list = list(map(int,input().split()))
d_list.sort()
# print(d_list)
if d_list[0] != 0:
    print(0)
    sys.exit()

for i in range(1,n):
    if d_list[i] == d_list[i-1]:
        now_strk += 1
    elif d_list[i] != d_list[i-1] and (d_list[i-1] != 1 or d_list[i-1] != 0):
        ans *= pre_strk ** now_strk
        pre_strk = now_strk
        now_strk = 1
        # print(ans)
    else:
        pre_strk = now_strk
        now_strk = 1
ans *= pre_strk ** now_strk
print(ans)

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

prev = 1
if 0 in m:
    s = 1
    for i in range(n ** 5):
        if not i in m:
            break
        v = m[i]

        s *= (prev ** v) % 998244353
        prev = v
else:
    s = 0

print(s)

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
    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:
import numpy as np
NUMBER = 998244353

N = int(input())
D = list(map(int, input().split()))
bincnt = np.bincount(D)
if (bincnt==0).sum() > 0:
    print('0')
else:
    val = 1
    for i in range(2, bincnt.shape[0]):
        for _ in range(bincnt[i]):
            val = (val*bincnt[i-1]%NUMBER)
    print(val)

Submission status: Wrong Answer

Solution code:
import sys
import collections as co
n = int(input())
d = list(map(int,input().split()))
mod = 998244353
ans = 1
if d[0] != 0:
    print(0)
    sys.exit()

else:

    tmp = co.Counter(d)
    #tmp = d.items()
    #print(tmp)
    if tmp[0] != 1:
        print(0)
        sys.exit()
    for i in range(1,len(tmp)):
        ans *= (tmp[i-1] ** tmp[i]) % mod

print(ans)

Submission status: Wrong Answer

Solution code:
import sys; readline = sys.stdin.readline
from collections import deque

from collections import Counter
P = 998244353
N = int(readline())
D = list(map(int, readline().split()))

c = Counter(D)
c = sorted(c.items(), key=lambda x:x[0])

def mod_pow(a, b):
    ret = 1
    for i in range(b):
        ret = ret * a % P
    return ret

if c[0][0] != 0 or c[0][1] != 1:
    print(0)
else:
    ans = 1
    for i in range(1, len(c)):
        if c[i - 1][0] != c[i][0] - 1:
            print(0)
            exit(0)
        ans = ans * mod_pow(c[i-1][1], c[i][1]) % P
    print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
D = groupby(sorted(list(map(int, input().split()))))
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:
import bisect

n = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
  print(0)
else:
  c = 1
  temp = 1
  D.sort()
  m = max(D)
  for i in range(m+1):
    a = bisect.bisect_right(D, i)
    d = a - temp
    temp = a
    if d == 0 and i>0:
      print(0)
      exit()
    else:
      c *= i**d
  print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
a = [0] * (10 ** 5)
if d[0] != 0 or d.count(0) != 1:
  print(0)
  exit()
for i in d:
  a[i] += 1
now = a[1]
if now == 0:
  if n == 1:
    print(1)
    exit()
  else:
    print(0)
    exit()
ans = 1
now_sum = now + 1
for i in a[2:]:
  if not i:
    if n != now_sum:
      ans = 0
    break
  else:
    ans *= pow(now, i, mod)
  now_sum += i
  now = i
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()]
tree = [(D[i], i) for i in range(N)]
tree.sort(key=lambda x: x[0])

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

ans = 1
mod = 998244353
b = 1
depth = 0

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	d = list(map(int,input().split()))
	z = defaultdict(int)
	for i in d:
		z[i] += 1
	mx = max(d)
	for i in range(mx+1):
		if z[i] == 0:
			print(0)
			return
	if(z[0]!=1):
		print(0)
		return
	ans = 1
	for i in reversed(range(1,mx+1)):
		ans *= z[i-1]**z[i]
	print(ans%998244353)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

Solution code:
import sys

pre_strk = 1
now_strk = 1
ans = 1
n = int(input())
d_list = list(map(int,input().split()))
d_list.sort()
print(d_list)
if d_list[0] != 0:
    print(0)
    sys.exit()

for i in range(1,n):
    if d_list[i] == d_list[i-1]:
        now_strk += 1
    elif d_list[i] != d_list[i-1] and (d_list[i-1] != 1 or d_list[i-1] != 0):
        ans *= pre_strk ** now_strk
        pre_strk = now_strk
        now_strk = 1
        print(ans)
    else:
        pre_strk = now_strk
        now_strk = 1
ans *= pre_strk ** now_strk
print(ans)

Submission status: Wrong Answer

Solution code:
n,*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*=m**n
print(a%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

B = int(input())
Dlist = list(map(int, input().split()))

A = 998244353

D_max = max(Dlist)
cnt = [0] * (D_max + 1)

dic = Counter(Dlist)
for k, v in dic.items():
    cnt[k] = v

ans = cnt[0]

if ans != 1:
    print(0)

else:
    for i in range(D_max):
        ans = ans * (cnt[i] ** cnt[i+1])

    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def resolve():
    n = int(input())
    d = list(map(int, input().split()))
    c = Counter(d)
    m = max(d)
    ans = 1
    if d[0] != 0 or c[0] != 1:
        print(0)
        return
    for i in range(1, m + 1):
        if c[i] == 0:
            print(0)
            return
        ans *= c[i - 1]**c[i]
    print(ans)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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


if D[0] != 0 or 0 in D[1:]:
    ans = 0
else:
    num = [0 for i in range(max(D)+1)]
    ans = 1
    cnt = 1
    for i in range(n):
        num[D[i]] += 1
    for i in range(len(num)):
        ans = ans * (cnt ** num[i] % 998244353)
        cnt = num[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# 累乗 x^n
def pow(x,n):
    global p
    res=1
    prod=x
    while n>0:
        if n%2==1:
            res=(res*prod)%p
        prod=(prod*prod)%p
        n//=2
    return res

p=998244353

N=int(input())
D=list(map(int,input().split())) # 頂点は0-initial

f=True
if D[0]!=0:
    f=False
else:
    C=Counter(D)
    if C[0]>1:
        f=False
    else:
        dmax=max(C.values())    
        for d in range(1,dmax):
            if d not in C:
                f=False
    if f:
        v=[C[i] for i in range(dmax+1)]
        ans=1
        for d in range(1,dmax):
            ans=(ans*pow(v[d],v[d+1]))%p
if f:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter 
import sys

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

mod = 998244353

D.sort()
d = list(Counter(D).items()) 

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

ans = 1
for i in range(1,len(d)):
    for _ in range(d[i][1]):
        ans *= i % mod
        ans = ans % mod
    ans = ans % mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = min(d)
max_d = max(d)
mod = 998244353

if min_d == max_d or d.count(min_d) >= 2:
    print(0)
    sys.exit()
count = [1 for _ in range(max_d-min_d+1)]
for i in range(min_d, max_d+1):
    count[i-min_d] = d.count(i)
    if count[i-min_d] == 0:
        print(0)
        sys.exit()
ans = count[1]
for i in range(1,max_d-min_d):
    n = count[i]-1
    m = count[i+1]
    ans *= (math.factorial(n+m)//(math.factorial(n)*math.factorial(m)))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
if D[0] > 0:
    print(0)
    exit()
mod = 998244353
X = defaultdict(int)

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

M = max(D)
ans = 1
for i in range(1, M):
    if X[i] == 0:
        ans = 0
        break
    ans *= pow(X[i], X[i+1], mod)
    ans %= mod
print(ans%mod)