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


# 累乗
def power(a, n, p):
    bi = str(format(n, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res


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

cnt = defaultdict(int)
for d in D:
    cnt[d] += 1

if cnt.get(0) != 1:
    print(0)
    exit(0)
ans = 1
for i in range(1, max(D) + 1):
    if cnt.get(i) is None:
        print(0)
        exit(0)
    num = power(cnt[i - 1], cnt[i], MOD)
    ans = (ans % MOD) * (num % MOD) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n,*d=map(int,open(0).read().split())
e=[0]*n
for i in d:e[i]+=1
a=d[0]<1
for x,y in zip(e,e[1:]):a=a*x**y%998244353
print(a)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
if dp[0] != 1 and l[0]!=0:
    print(0)
    exit()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]%MOD

print(res)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = list(map(int,input().split()))
MOD = 998244353
dp = [0]*a
for i in l:
    dp[i]+=1
res = 1
# print(dp)
l.sort()

for i in l[1:]:
    # print(i)
    res*=dp[i-1]

print(res%MOD)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    D = LI()

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

    if any([d == 0 for d in D[1:]]):
        print(0)
        return

    MAX_D = max(D)
    node = [0] * (MAX_D + 1)

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

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




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    dic = defaultdict(int)
    mod = 998244353
    for i in D:
        dic[i] += 1

    if dic[0]!=1:
        print(0)
        exit()
    ans = 1
    for i in range(1,max(dic.keys())+1):
        ans *= dic[i-1]**dic[i]
        ans %= mod
    
    print(ans)    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections as c
N = int(input())
d = list(map(int, input().split()))
D = c.Counter(d)
mod = 998244353
cnt = 0
ans = 1
DD = sorted(list(D.keys()))
for i in DD:
	if i != cnt:
		ans = 0
		break
	if i == 0:
		if D[0] != 1:
			ans = 0
			break
		else:
			cnt += 1
			continue

	n = D[cnt-1]
	m = D[cnt]

	for _ in range(m):
		ans *= n
		ans %= mod

	cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def main():
    N = int(input())
    D = [int(x) for x in input().split()]
    dic = defaultdict(int)
    for i in D:
        dic[i] += 1

    if dic[0]!=1:
        print(0)
        exit()
    ans = 1
    for i in range(1,max(dic.keys())+1):
        ans *= dic[i-1]**dic[i]
    print(ans)    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

if D[0]==0:
    count=1
    for i in range(1,N):
        count*=D[i]
        count%=mod
    print(count)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(max(lis)+1)]
for nu in lis:
    num[nu] += 1
ans = 1
for i in range(max(lis)):
    if num[i] == 0:
        print(0)
        exit()
    for _ in range(num[i+1]):
        ans *= num[i]
        ans %= 998244353
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
num = [0 for i in range(max(lis)+1)]
for nu in lis:
    num[nu] += 1
ans = 1
for i in range(max(lis)):
    if num[i] == 0:
        print(0)
        exit()
    for _ in range(num[i+1]):
        ans *= num[i]
        ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
layer=[0]*N

mx=0
for item in D:
    if item == 0:
        print("GYAAAAAAAAAAAAAA")
    layer[item]+=1
    mx=max(mx,item)

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

ans=1
for i in range(mx):
    ans*=(layer[i]**layer[i+1])

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
layer=[0]*N

mx=0
for item in D:
    layer[item]+=1
    mx=max(mx,item)

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

ans=1
for i in range(mx):
    ans*=(layer[i]**layer[i+1])

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
def mod_pow(x, n, MOD):
    if n == 0:
        return 1
    if n % 2 == 0:
        result = mod_pow(x * x, n // 2, MOD)
        return result % MOD
    else:
        result = x * mod_pow(x, n - 1, MOD)
        return result % MOD

from collections import Counter        

MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
max_num = max(D)

count = Counter(D)
ans = 1

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

for i in range(max_num):

    ans *= mod_pow(count[i], count[i+1], MOD)
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
layer=[0]*N

mx=0
for item in D:
    layer[item]+=1
    mx=max(mx,item)

if layer[0]>1:
    print(0)
    exit()

ans=1
for i in range(mx):
    ans*=layer[i]**layer[i+1]

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
layer=[0]*N

mx=0
for item in D:
    layer[item]+=1
    mx=max(mx,item)

ans=1
for i in range(mx):
    ans*=layer[i]**layer[i+1]

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
layer=[0]*N

mx=0
for item in D:
    layer[item]+=1
    mx=max(mx,item)

ans=1
for i in range(mx):
    ans*=layer[i]**layer[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
dic=dict()
for i in range(n):
  if d[i] not in dic:
    dic[d[i]]=1
  else:
    dic[d[i]]+=1
if 0 not in dic or dic[0]>1:
  print(0)
else:
  l=list(dic.items())
  l.sort()
  ans=1
  for i in range(len(l)-1):
    if l[i][0]+1==l[i+1][0]:
      ans*=l[i][1]**l[i+1][1]
    else:
      print(0)
      exit()
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
dic=dict()
for i in range(n):
  if d[i] not in dic:
    dic[d[i]]=1
  else:
    dic[d[i]]+=1
if 0 not in dic:
  print(0)
else:
  l=list(dic.items())
  l.sort()
  ans=1
  for i in range(len(l)-1):
    if l[i][0]+1==l[i+1][0]:
      ans*=l[i][1]**l[i+1][1]
    else:
      print(0)
      exit()
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
#https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_b?lang=en
#B - Counting of Trees
"""
sort, and then check how many next levels we have against the previes level
keep a prevcount, and each level is prev level ** cur elvel
"""
N = gi()
cnt = [0] * N

MOD = 998244353

max_d = 0

for i in range(N):
    d = gi()
    cnt[d] += 1
    max_d = max(max_d, d)


def run():
    if cnt[0] != 1:
        print(0)
        return

    ans = 1
    for i in range(1, max_d + 1):
        if cnt[i] == 0:
            print(0)
            return
        for _ in range(cnt[i]):
            ans *= cnt[i - 1]
            ans %= MOD

    print(ans)


run()

Submission status: Wrong Answer

Solution code:
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
#https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_b?lang=en
#B - Counting of Trees
"""
sort, and then check how many next levels we have against the previes level
keep a prevcount, and each level is prev level ** cur elvel
"""
N = gi()
D = [0] * N

MOD = 998244353

for i in range(N):
    D[i] = gi()

D.sort()
D.append(-1)

#print(D)


def run():
    if (D[0]):
        print(0)
        return

    prev_cnt = 1  #virtual parent node here
    cur_cnt = 1
    cur_lvl = 0

    ans = 1
    for i in range(1, N + 1):
        if (D[i] == cur_lvl):
            cur_cnt += 1
            continue
        elif (D[i] > cur_lvl + 1):
            print(0)
            return

        from_cur = 1
        for j in range(cur_cnt):
            from_cur *= prev_cnt
            from_cur %= MOD

        #print(i, D[i], prev_cnt, cur_cnt, from_cur)

        ans *= from_cur
        ans %= MOD
        prev_cnt = cur_cnt
        cur_cnt = 1
        cur_lvl = D[i]

    print(ans)


run()

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(D)

if c[0] != 1:
    print(0)
else:
    ans = 1
    buf = 1
    for i in range(max(D) + 1):
        if c[i] == 0:
            print(0)
            break
        ans *= buf ** c[i]
        buf = c[i]
    else:
        print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(D)

if c[0] != 1:
    print(0)
else:
    ans = 1
    buf = 1
    for i in range(max(D) + 1):
        if c[i] == 0:
            print(0)
            break
        ans *= buf ** c[i]
        buf = c[i]
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def print_0():
  print(0)
  exit()

MOD = 998244353
N = int(input())
D = Counter(map(int,input().split()))
if 0 not in D or D[0]!=1: print_0()

max_rank = max(D.keys())
ans = 1
for i in range(max_rank+1):
  if i not in D:
    print_0()
  elif i not in [0,1]:
    ans *= D[i-1]**D[i]
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter
def print_0():
  print(0)
  exit()

MOD = 998244353
N = int(input())
D = Counter(map(int,input().split()))
if 0 not in D or D[0]!=1: print_0()

max_rank = max(D.keys())
ans = 1
for i in range(max_rank+1):
  if i not in D:
    print_0()
  elif i != 0:
    ans *= D[i-1]**D[i]
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353
N = int(input())
D = Counter(map(int,input().split()))
max_rank = max(D.keys())
ans = 1
for i in range(max_rank+1):
  if i not in D:
    print(0)
    exit()
  elif i != 0:
    ans *= D[i-1]**D[i]
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353
N = int(input())
D = Counter(map(int,input().split()))
max_rank = max(D.keys())
ans = 1
for i in range(max_rank+1):
  if i not in D:
    print(0)
    exit()
  elif i != 0:
    ans *= D[i-1]**D[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
dd = list(map(int,input().split()))
dic_c = Counter(dd)

zero_flag = False
if dic_c[0]!= 1 or dd[0]!=0 :
  zero_flag = True

for i in range(max(dd)):
  if dic_c[i] == 0 :
    zero_flag = True

if zero_flag:
  print(0)  
else:
  ans = 1
  for i in range(1,max(dd)):
    ans *= dic_c[i]**dic_c[i+1]
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
x=max(d)
li=[0]*(x+1)
for i in range(n):
    li[d[i]]+=1
if d[0]!=0:
    print(0) 
else:
    ans=1
    for i in range(2,len(li)):
        ans*=li[i-1]**li[i]    
    print(ans)

Submission status: Wrong Answer

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

N = int(input())
D = defaultdict(int)
for i,x in enumerate(input().split()):
    if i == 0 and x != 0:
        print(0)
        exit()
    D[int(x)] += 1
D_len = len(D)

MOD = 998244353

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

answer = 1
for i in range(1,D_len):
    if D[i] == 0:
        answer = 0
        break
    tmp = 1
    for _ in range(D[i]):
        tmp = (tmp * D[i-1]) % MOD
    answer = (answer * tmp) % MOD

print(answer)

Submission status: Wrong Answer

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

N = int(input())
D = defaultdict(int)
for i in input().split():
    D[int(i)] += 1
D_len = len(D)

MOD = 998244353

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

answer = 1
for i in range(1,D_len):
    if D[i] == 0:
        answer = 0
        break
    tmp = 1
    for _ in range(D[i]):
        tmp = (tmp * D[i-1]) % MOD
    answer = (answer * tmp) % MOD

print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
D = {}
for i in range(N):
  if A[i] in D:
    D[A[i]] += 1
  else:
    D[A[i]] = 1
sorted(D)
S = 1
if A[0] == 0 and D[0] == 1:
  for i in D:
    if i != M:
      if i + 1 not in D:
        S = 0
        break
      else:
        S *= D[i] ** D[i+1]
else:
  S = 0
print(S)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
M = max(A)
D = {}
for i in range(N):
  if A[i] in D:
    D[A[i]] += 1
  else:
    D[A[i]] = 1
sorted(D)
S = 1
if A[0] == 0 and D[0] == 1:
  for i in D:
    if i != M:
      if i + 1 not in D:
        S = 0
        break
      else:
        S *= D[i] ** D[i+1]
print(S)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(max(D)+1)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 0 or C[0] != 1:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(max(D)+1)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 1 or C[0] != 1:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(N)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 1 or C[0] != 1:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(N)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 1 or C[0] != 1:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(N)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 1 or C[0] >= 2:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(N)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 0 or C[0] >= 2:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = np.array(input().split(), dtype=np.int64)

C = np.zeros(N)
for i in range(N):
    C[D[i]] += 1
    
if D[0] != 0 or C[0] >= 2:
    ans = 0
    print(ans)
    exit()

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

counter = defaultdict(int)
for d in D[1:]:
    if d == 0:
        print(0)
        exit()
    counter[d] += 1

ans = 1
for i in range(1, max(D)):
    ans *= counter[i] ** counter[i+1]
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()

counter = defaultdict(int)
for d in D:
    counter[d] += 1

ans = 1
for i in range(1, max(D)):
    ans *= counter[i] ** counter[i+1]
print(ans)

Submission status: Wrong Answer

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

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

a.sort()
b = set(a[1:])
if 0 in b:
    print(0)
    exit()

count_pre = 1
count_now = 1
ans = 1
for i in range(1, n-1):
    if a[i] == a[i+1]:
        count_now += 1
    else:
        ans *= (count_pre ** count_now)
        ans %= 998244353
        count_pre = count_now
        count_now = 1
ans *= (count_pre ** count_now)
ans %= 998244353

print(ans)

Submission status: Wrong Answer

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

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

a.sort()
count_pre = 1
count_now = 1
ans = 1
for i in range(1, n-1):
    if a[i] == a[i+1]:
        count_now += 1
    else:
        ans *= (count_pre ** count_now)
        ans %= 998244353
        count_pre = count_now
        count_now = 1
ans *= (count_pre ** count_now)
ans %= 998244353

print(ans)

Submission status: Wrong Answer

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

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

a.sort()
count_pre = 1
count_now = 1
ans = 1
for i in range(1, n-1):
    if a[i] == a[i+1]:
        count_now += 1
    else:
        ans *= (count_pre ** count_now)
        count_pre = count_now
        count_now = 1
ans *= (count_pre ** count_now)

print(ans)

Submission status: Wrong Answer

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

MOD = 998244353

from collections import defaultdict

count = defaultdict(int)

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

tmp = 0
ans = 0
check = 0
for i in range(N):
    if i == 0:
        if count[i] == 1:
            ans = 1
            tmp = 1
            check += 1
        else:
            print (0)
            exit()
    else:
        ans *= pow(tmp, count[i], MOD)
        tmp = count[i]
        check += count[i]
    # print (i)
    ans %= MOD

    if check == N:
        break
    
    if count[i] == 0:
        print (0)
        exit()

print (ans % MOD)

Submission status: Wrong Answer

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

MOD = 998244353

from collections import defaultdict

count = defaultdict(int)

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

tmp = 0
ans = 0
check = 0
for i in range(N + 1):
    if i == 0:
        if count[i] == 1:
            ans = 1
            tmp = 1
            check += 1
        else:
            print (0)
            exit()
    else:
        ans *= pow(tmp, count[i], MOD)
        tmp = count[i]
        check += count[i]
    # print (i)
    ans %= MOD

    if check == N:
        break
    
    if count[i] == 0:
        print (0)
        exit()

print (ans % MOD)

Submission status: Wrong Answer

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

MOD = 998244353

from collections import defaultdict

count = defaultdict(int)

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

tmp = 0
ans = 0
check = 0
for i in range(N + 1):
    if i == 0:
        if count[i] == 1:
            ans = 1
            tmp = 1
            check += 1
        else:
            print (0)
            exit()
    else:
        ans *= pow(tmp, count[i], MOD)
        tmp = count[i]
        check += count[i]
    # print (i)
    ans %= MOD

    if check == N:
        break

print (ans % MOD)

Submission status: Wrong Answer

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

if d[0]>0:
  print(0)
  exit()
else:
  d_max=max(d)
  k=1
  m=[0for i in range(d_max+1)]
  for i in range(1,n):
    if d[i]==0:
      k=0
    m[d[i]]+=1
  for i in range(1,d_max+1):
    if m[i]==0:
      k=0
  if not k:
    print(0)
  else:
    ans=1
    for i in range(1,d_max):
      ans*=m[i]**m[i+1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import cmath
import sys

INF=10**18
MOD=998244353
MAX=10**5+7

def main():
    N=int(input())
    D=list(map(int, input().split()))
    cnt=[0]*(N+1)

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

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

    ans=1
    for  i in range(1, max(D)+1):
        ans=ans*pow(cnt[i-1], cnt[i], MOD)%MOD
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

fq = [0] * (N + 10)

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

if not(D[0] == 0 or fq[0] == 1):
    print(0)
    exit()

ans = 1
for i in range(2, N+1):
    ans = (ans * (fq[i-1] ** fq[i] % 998244353)) % 998244353

print(ans)

Submission status: Wrong Answer

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

fq = [0] * (N + 10)

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

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

ans = 1
for i in range(2, N+1):
    ans = (ans * (fq[i-1] ** fq[i] % 998244353)) % 998244353

print(ans)

Submission status: Wrong Answer

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

fq = [0] * (N + 10)

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

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

ans = 1
for i in range(2, N+1):
    ans = (ans * (fq[i-1] ** fq[i] % 998244353)) % 998244353

print(ans)

Submission status: Wrong Answer

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

fq = [0] * (N + 10)
for d in D:
    fq[d] += 1

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

ans = 1
for i in range(2, N+1):
    ans = (ans * (fq[i-1] ** fq[i] % 998244353)) % 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
#存在しないとき
if d[0] != 0:
    print(0)
    exit()
d0 = sorted(d)
for i in range(n-1):
    if d0[i+1] -d0[i] > 1:
        print(0)
        exit()
if d0[1] == 0:
    print(0)
    exit()
#############
dmax = d0[n-1]
if dmax == 1:
    print(1)
    exit()
l1 = 0
k = 1
for i in range(1,n):  
    if d0[i] == 1:
        l1 += 1
        k += 1
    else:
        break
l = [1,l1]
#print(l1)
ans = 1
for i in range(2,dmax+1):
    tmp = 0
    for j in range(k,n):
        if d0[j] == i:
            tmp += 1
            k += 1
        else:
            break
    #print(tmp)
    l.append(tmp)
    ans *= (l[i-1] ** l[i]) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = list(map(int, input().split()))
D = collections.Counter(d)
ans = 1
mod = 998244353
if d[0] != 0:
    print(0)
    exit()
if D[0] != 1:
    print(0)
    exit()
for i in range(1, max(d)):
    ans *= D[i]**D[i + 1] % mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
if lists[0]!=0:
    print(0)
elif lists[0]==0:
    c=1
    lists=sorted(lists)
    flag=True
    for _ in range(n-1):
        if lists[_+1]-lists[_]>1:
            flag=False
    if lists[1]==0:
        print(0)
    else:
            import collections
            lis=collections.Counter(lists)
            dic=dict(lis)
            del dic[0]
            uselist=[]
            for some in dic.values():
                uselist.append(some)
            for i in range(len(uselist)-1):
                for j in range(uselist[i+1]):
                    c*=uselist[i]
                    c=c%(998244353)
            print(c)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=1
lists=list(map(int,input().split()))
flag=True
if lists[0]!=0:
  flag=False
lists=sorted(lists)
for _ in range(n-1):
    if lists[_+1]-lists[_]>1:
        flag=False
if lists[0]>0:
    flag=False
elif lists[0]==0:
    if lists[1]==0:
        flag=False
    else:
        flag=True
        import collections
        lis=collections.Counter(lists)
        dic=dict(lis)
        del dic[0]
        uselist=[]
        for some in dic.values():
            uselist.append(some)
        for i in range(len(uselist)-1):
          for j in range(uselist[i+1]):
            c*=uselist[i]
            c=c%(998244353)

            
if flag:
  print(c)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=1
lists=sorted(list(map(int,input().split())))
flag=True
for _ in range(n-1):
    if lists[_+1]-lists[_]>1:
        flag=False
if lists[0]!=0:
    flag=False
elif lists[0]==0:
    if lists[1]==0:
        flag=False
    else:
        import collections
        lis=collections.Counter(lists)
        dic=dict(lis)
        del dic[0]
        uselist=[]
        for some in dic.values():
            uselist.append(some)
        for i in range(len(uselist)-1):
          for j in range(uselist[i+1]):
            c*=uselist[i]
            c=c%(998244353)

            
if flag:
  print(c)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
#B
mod = 998244353
N = int(input())
D = list(map(int,input().split()))

if D[0] != 0:
    print(0)
else:
    MD = max(D)
    C = [0]*(MD+1)
    for d in D:
        C[d]+=1
    ans = 1
    for i in range(MD):
        ans *= pow(C[i],C[i+1],mod)
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
#B
mod = 998244353
N = int(input())
D = list(map(int,input().split()))

if D[0] != 0:
    print(0)
else:
    D.sort()
    C = [0 for i in range(N)]
    for d in D:
        C[d]+=1
    ans = 1
    for i in range(N-1):
        ans *= pow(C[i],C[i+1],mod)
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1

if a[0] or count.count(0)>1:
    print(0)
    exit()
for i in range(1,m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1

if a[0] or count.count(0)-1:
    print(0)
    exit()
for i in range(1,m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1
if a[0]:
    print(0)
    exit()
for i in range(m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1
if a[0]!=1:
    print(0)
    exit()
for i in range(m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
m=max(a)
count=[0]*(m+1)
for i in a:
    count[i] += 1

for i in range(m):
    if count[i]==0 and count[i+1]:
        print(0)
        exit()

ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

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

count=[0]*n
for i in range(n):
    count[i]=a.count(i)

for i in range(1,n-1):
    if count[i-1] and not count[i] and count[i+1]:
        print(0)
        exit()

while count.count(0):
    count.remove(0)
ans=1

for i in range(len(count)-1):
    ans*=count[i]**count[i+1]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
print("0")

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
D={}
T=list(map(int,input().split()))
for i in range(N):
    if D.get(T[i],None)==None:
        D[T[i]]=1
    else:
        D[T[i]]+=1

Max=max(D)
Min=min(D)
Len=len(D)
Item=sorted((D.items()))
if(Item[0][1]!=1):
        print("0")
        exit()
for i in range(Len):
    if(Item[i][0]!=i):
        print("0")
        exit()
ans=1
for i in range(1,Len):
    ans = (ans * (Item[i-1][1]**Item[i][1])) % 998244353
    
print(ans)