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()))
#n = len(d)
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
ans = 1
try:
  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)
  exit()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for _d in D:
        distance[_d[0]] += 1

    if min(d) != 0:
        print(0)
        return

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            # print('n', n, 'r', r, 'c', c)
            ans = ans * n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

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

    if max(D) >= N:
        print(0)
        exit()


    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from math import factorial
n = int(input())

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

D.sort()
#print(D)
num = 1
m = 0
flag = 1
mb = 0
for i in D:
    if i == 0:
        mb += 1
    else:
        break
#print(mb)
S = mb

for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
        flag = 1
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        if flag == 0:
            num += 1
        else:
                
            a = mb ** m
            S *= a
            mb = m
            m = 1
            num += 1
            flag = 0
    
a = mb ** m
S *= a
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n1 = int(input()) - 1
d = list(map(int, input().strip().split()))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    max_path = max(d)
    flag = True
    v = []
    for i in range(1, max_path+1):
        v.append(d.count(i))
    for j in range(len(v)):
        if v[j] == 0:
            flag = False
    if flag:
        num = 1
        hh = 1
        for h in range(len(v)):
            if hh == 1:
                num *= 1
            elif v[h] == 1:
                num *= hh
            else:
                num *= hh * (v[h] + 1)

            hh = v[h]

        print(num % mod)

    else:
        print(0)

Submission status: Wrong Answer

Solution code:
a=int(input())
d=[int(x) for x in input().split()]
d.sort()
z=max(d)
w=d.count(0)
if d[0]==0 and w==1:
  n=1
  for i in range(z):
    x=i+1
    r=d.count(x-1)
    q=d.count(x)
    n=(n*(r**q%998244353)%998244353)
    if n==0:
      break
  print(n)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
else:
    import collections
    c = collections.Counter(d)
    c_sorted = sorted(c.items())
    u = [x[1] for x in c_sorted]
    u.remove(u[0])
    if len(u)!= max(d):
        print(0)
    else:
        x = 1
        for i in range(len(u)-1):
            x = x * (u[i] ** u[i+1])
                 
        print(x%998244353)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
d = list(map(int, input().split()))
heapq.heapify(d)
if d[0] != 0:
    print(0)
else:
    pre = -1
    num = 0
    ans = 1
    frag = False
    dif = 0
    for i in range(len(d)):
        if d[0] == 0:
            if i > 0:
                print(0)
                break
            else:
                pre = 0
                heapq.heappop(d)
                continue
        if d[0] == pre:
            num += 1
            if i == n-1:
                ans *= (pre-dif)**num
            heapq.heappop(d)
        elif d[0] - pre > 1:
            print(0)
            break
        else:
            if i == 1:
                num = 1
                pre = d[0]
                heapq.heappop(d)
                continue
            if frag:
                dif += 1
                frag = False
            else:
                ans *= (pre-dif)**num
            pre = d[0]
            if i == n-1:
                ans *= pre
            if num == 1:
                frag = True
            num = 1
            heapq.heappop(d)
    else:
        print(ans)

Submission status: Wrong Answer

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

sum = 1
if d[0] == 0:
  for i in range(1, n):
    sum *= int(d[i]) 
  print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
vertex_list = list(map(int, input().split()))
if vertex_list[0] != 0:
    print(0)
else:
    maxx = max(vertex_list)
    list = []
    mark = 0
    ans = 1
    for i in range(1,maxx+1):
        count = vertex_list.count(i)
        if count == 0:
            marc = -1
            break
        ans *= (i) ** count
    if mark == -1:
        print(0)
    else:
        print(ans)

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:
      for j in range(b):
        c *= a % 998244353
        c = c % 998244353
    elif s[i] == deep + 1:
      for j in range(b):
        c *= a % 998244353
        c = c % 998244353
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

set_d = set(d)
list_d = list(set_d)
list_d.sort()
dict_d = Counter(d)

if dict_d[0] == 1:
    pass
else:
    print(0)
    exit()

ans = 1
cnt = 1
temp = 0
check = 1

for i in list_d:
    if i == 0:
        continue
    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = (ans * check**cnt)%998244353
    check = cnt
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    # ar = np.array(ar)
    # tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])

    if ngflg:
        print("0")
    else:
        ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        print(np.prod(ans_ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0) 
    
    else:
        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

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

            ans *= tmp**j
            print(ans)
            tmp = j

        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
 
c = Counter(D)
max_D = max(D)
if c[0]!=1:
  print(0)
  
elif max_D<=1:
  print(1)
  
else:
  answer=1
  for i in range(2,max_D+1):
    c_i2 = c[i]
    c_i1=c[i-1]
    answer *= c_i1**c_i2
    
  print(answer%998244353)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
N=int(input())
D=input().split()
#Di=[int(n) for n in D]
#if Di[0] != 0:
T=[]
D_dict=Counter(D)
D_keys=list(D_dict.keys())
D_keyi=[int(n) for n in D_keys]
#print(D_keyi)
maxD=max(D_keyi)
#print(maxD)
#print(list(range(maxD+1)))
D_keyi.sort()
ans=1
if D[0] != '0' or D_dict['0']!=1 or D_keyi != list(range(maxD+1)):
    print(0)
else:
    for i in range(N):
        T.append(D_dict[str(i)])
    for i in range(len(T)-1):
        ans=ans*(T[i]**T[i+1])
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
if D[0] > 0:
    print(0)
else:
    new_l = [0 for n in range(N)]
    ini = D[0]
    for n in range(N):
        new_l[D[n]] += 1
    res = 1
    for n in range(len(new_l)-1):
        res *= new_l[n]**new_l[n+1]
        res = res%998244353
    print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for d in D:
        distance[d[0]] += 1

    if min(d) != 0:
        print(0)
        return

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            # print('n', n, 'r', r, 'c', c)
            ans = ans ** n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

set_d = set(d)
list_d = list(set_d)
list_d.sort()
dict_d = Counter(d)

if dict_d[0] == 1:
    pass
else:
    print(0)
    exit()

ans = 1
cnt = 1
temp = 0
check = 1

for i in list_d:
    if i == 0:
        continue
    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = (ans * check**cnt)%998244353
    check = cnt
    
print(ans%998244353)
print(list_d)
print(dict_d)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
D = list(map(int, input().split()))
l = [0] * (N-1)
if D[0] != 0:
    print(0)
    exit()
for i in range(1, N):
    l[D[i]-1] += 1
# print(*l)
ans = 1
for i in range(1, len(l)):
    if l[i] != 0:
        ans *= l[i-1] ** l[i]
print(ans)

Submission status: Wrong Answer

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

sum = 1
if d[0] == 0:
  for i in range(1, n):
    if int(d[i]) > 1:
      sum *= int(d[i]) 
  print(sum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353

N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
C = Counter(D)
ans = 1
for i in range(1, max(D)+1):
    if C[i] == 0:
        ans = 0
        break
    else:
        ans *= pow(C[i-1], C[i], MOD)
        ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
c = collections.Counter(D)
##print(c)
ans = 1
##print(max(D))
for i in range(1, max(D)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= c[i-1] ** c[i]
    ans = ans % mod
    ##print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
d = list(map(int, input().split()))
m = {}
ans = 1

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

for i in range(n):
    num = d[i]
    if num in m:
        m[num] += 1
    else:
        m[num] = 1

#print(m)
#print(max(m))
maxV = max(m.keys())

#for i in range(1, max(m)+1):
#for i in range(0, max(m)):
for i in range(0, maxV):
    if i not in m or i + 1 not in m:
        print(0)
        sys.exit()
    prevCnt = m[i]
    curCnt = m[i+1]
    # prevCnt = m[i] % 998244353
    #curCnt = m[i+1] % 998244353
    ans *= prevCnt ** curCnt
    #ans *= (prevCnt ** curCnt) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

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

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0

    res = 1
    for i in range(2, iter+1):
        res *= ( (c[i-1]%MOD)**c[i])%MOD
        res %= MOD
    return res%MOD

res = count(c, max(d))
print(res)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    ar = np.array(ar)
    # tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])

    if ngflg:
        print("0")
    else:
        ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        print(np.prod(ans_ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
d.sort()
acount=1
count=1
sd=set(d)
sd=list(sd)
s=0

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(d)>1 and d[-1]!=d[-2]:
  ans*=count
elif len(d)>1 and d[-1]==d[-2]:
  ans*=(count**acount)

  
for i in range(len(sd)-1):
  if sd[i]+1!=sd[i+1]:
    s=1
if s==0:
  if d[0]==0:
    print(ans%998244353)
  elif d[0]!=0:
    print(0)
else:
  print(0)

Submission status: Wrong Answer

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

sum = 1
if d[0] == 0 and d.count(0)==1:
  for i in range(1, n):
    if int(d[i]) > 1:
      sum *= int(d[i]) 
  print(sum)
else:
  print("0")

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx == 0:
        count *= 1
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
if len(tree_list) == 1:
    print(1)
else:
    print(count%998244353)

Submission status: Wrong Answer

Solution code:
# 指定された距離で何個の木を作成することができるかを計算する
import bisect
import itertools
N = int(input())
D = list(map(int, input().split()))
node_dis = [1] # 距離iのノードの個数をi番目の要素として格納したリスト
flag_none = False

# 頂点１から深さは決まっている.深さni毎に前のni-1のノードから重複を許してc_ni個選んでノードに繋げばよい
if not D[0] == 0:
    print(0)
    flag_none = True

else:
    D.sort()  # 昇順でソート
    for i in range(1,N):
        if i == 1 and bisect.bisect_left(D,1) >= 2:  # 0が２つ以上ある場合
            print(0)
            flag_none = True
            break
        else:
            index = bisect.bisect_left(D,i+1)
            new_num = index - sum(node_dis)
            node_dis.append(new_num)
            if new_num == 0:
                if not index == N:
                    print(0)
                    flag_none = True
                break

if flag_none == False:
    sum = 1
    for (ind, di) in enumerate(node_dis): 
        if ind > 0:
            sum *= node_dis[ind-1] ** di
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
D_n = [D.count(i) for i in range(max(D) + 1)]
#print(D_n)
#n1が0ではない、もしくは他に0がある
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    bi = str(format(D_n[i + 1],"b"))#2進表現に
    #print(D[i + 1])
    #print(bi)
    res = 1
    for j in range(len(bi)):
      res = (res*res) % mod
      if bi[j]=="1":
        res=(res*D_n[i]) % mod
    ans *= res
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = input()
if s[0] != 0:
    print(0)
    exit()
d = Counter(map(int, s.split()))
mod = 998244353

if 0 not in d or d[0] > 1:
    print(0)
    exit()
if n == 1:
    print(1)
    exit()

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

print(ans % mod)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
inputs = sys.stdin.readlines()

n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353

B = sorted(Counter(A).items())
C = [b[1] for b in B]
if all([i == k for i, (k, v) in enumerate(B)]) and A[0] == 1:
    ans = 1
    for i in range(1, len(C)-1):
        ans *= pow(C[i], C[i+1], MOD) % MOD
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for d in D:
        distance[d[0]] += 1

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

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            # print('n', n, 'r', r, 'c', c)
            ans = ans ** n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def ruijo(a, b, mod):
    x = 1
    
    for i in range(b):
        x = (x * a) % mod 
    
    return x


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

Sum = 1

for i in range(len(x)):

    if i != 0:
        Sum *= ruijo(x[i - 1], x[i], 998244353)%998244353
    else:
        Sum *= x[i]%998244353

print(Sum)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()] 
if a[0]!=0:
    print ("0")
else:
    a.sort()
    a = Counter(a)
    ans = 1
    for i in range(1,len(a)-1):   
        ans*=a[i]**a[i+1]
    print(ans)

Submission status: Wrong Answer

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

f=True
d={}
a=0
for i in range(N):
	if D[i] not in d:
		if D[i]==a:
			d[D[i]]=1
			a=D[i]+1
		else:
			f=False
			break
	else:
		d[D[i]] += 1

if not(f):
	print(0)
elif d[0]>1:
		print(0)
else:
	ans=1
	d = list(d.values())
	for i in range(1, len(d))[::-1]:
		ans *= (d[i-1]**d[i])%998244353
		ans %= 998244353
	print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial as fact
from collections import Counter

N = int( input() )
tree = list( map( int, input().split() ) )
ans = 1
if tree[0] != 0:
    print(0)
else:
    c = Counter(tree)
    if c[0] != 1:
        print(0)
    else:
        ans = 1
        a = c[1]
        for i in range( 2,len(c)):
            t = c[i]
            ans *= ( a**t )
            a = t
        print(ans)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
d = list(map(int, input().split()))
heapq.heapify(d)
if d[0] != 0:
    print(0)
else:
    pre = -1
    num = 0
    ans = 1
    frag = False
    dif = 0
    for i in range(len(d)):
        if d[0] == 0:
            if i > 0:
                print(0)
                break
            else:
                pre = 0
                heapq.heappop(d)
                continue
        if d[0] == pre:
            num += 1
            if i == n-1:
                ans *= (pre-dif)**num
            heapq.heappop(d)
        elif d[0] - pre > 1:
            print(0)
            break
        else:
            if i == 1:
                num = 1
                pre = d[0]
                heapq.heappop(d)
                continue
            if frag:
                pre = 1
                dif += 1
                frag = False
            ans *= (pre-dif)**num
            pre = d[0]
            if i == n-1:
                ans *= pre
            if num == 1:
                frag = True
            num = 1
            heapq.heappop(d)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0) 
    
    else:
        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

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

            ans *= tmp**j
            #print(ans)
            tmp = j

        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

N = int(input())
D = list(map(int,input().split()))
tree = []
ans = 1

for i in range(max(D)+1):
    tree.append(D.count(i))
    
if tree.count(0) > 0:
    print(0)
elif not tree[0] == 1:
    print(0)
else:
    for j in range(len(tree)-2):
        ans *= pow(tree[j+1],tree[j+2])%998244353
    print(ans)

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 N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        c = (tmp**cnt[i]) % mod
        ans *= c % mod
        tmp = cnt[i]
        ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = list(map(int,input().split()))
c = collections.Counter(d)
d.sort()
maxim = d[-1]
if d[0] != 0 or c[0] >= 2:
    print(0)
    exit()
else:
    ans = 1
    for i in range(1,maxim):
        ans *= c[i]**c[i+1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    ar = np.array(ar)
    # tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])

    if ngflg:
        print("0")
    else:
        # ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        print(np.prod(ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Wrong Answer

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

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

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

if max(d)+1 != len(c):
    print(0)
    sys.exit()

try:
    for i in range(1, len(c)-1):
        ans = (ans*c[i]**c[i+1]) % mod
except KeyError:
    print(0)
    sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
a=int(input())
d=[int(x) for x in input().split()]
d.sort()
z=max(d)
w=d.count(0)
if d[0]==0 and w==1:
  n=1
  for i in range(z):
    x=i+1
    r=d.count(x-1)
    q=d.count(x)
    n=(n*(r**q)%998244353)
    if n==0:
      break
  print(n)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
#B
N = int(input())
D_list = [int(s) for s in input().split(" ")]

res = 1
if D_list.count(0) == 1:
    for i in range(0, max(D_list)):
        if D_list.count(i)!=0:
            res *= D_list.count(i) ** D_list.count(i+1)
        else:
           res = 0
           break
else:
    res = 0

print(res % 998244353)

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:
      for j in range(b):
        c *= a % 998244353
    elif s[i] == deep + 1:
      for j in range(b):
        c *= a % 998244353
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0) 
    
    else:
        #d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        ans = 1
        tmp = 1
        for i,j in items:
            if i == 0:
                continue
            
            ans *= i**j
            #print(ans)
            #tmp = j
        
        #ans *= i*
        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
for i in range(len(d)):
    if i == 0 and d[i] != 0:
        print(0)
        exit()
    if i != 0 and d[i] == 0:
        print(0)
        exit()

e = collections.Counter(d)

e2 = dict(sorted(e.items()))
e3 = list(e2.values())
e4 = list(e2.keys())
print(e2)
print(e3)
print(e4)

tmp = 0
for i in e4:
    if i - tmp >= 2:
        print(0)
        exit()
    tmp = i

cntsum = 1
for i in range(1, len(e3)):
    cntsum *= e3[i - 1] ** e3[i]
print(cntsum%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
anslist=[0 for i in range(n+1)]
for j in lists:
    anslist[j]+=1

if anslist[0]!=1:
    print(0)
else:
    ans=1
    for j in range(n):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    Anslist=anslist[::-1]
    flag=False
    judge=True
    for j in range(n):
        if Anslist[j]>0 and not flag:
            flag=True
        if Anslist[j]==0 and flag:
            judge=False
    if judge:
        print(ans%(998244353))
    else:
        print(0)