Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

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

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
from collections import Counter
q=Counter(d)
if d[0]!=0 or q[0]>1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
 
cnt = 1
for i in range(1,max(d)+1):
    ans*=pow(q[i-1],q[i],mod)
    ans%=mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
N=int(input())
d=list(map(int,input().split()))
dd=[]
count=1
if d[0]!=0:
    count=0
for i in range(1,max(d)+1):
    dd.append(d.count(i))
# print(dd)
for i in range(0,max(d)):
    count *= pow(i+1,dd[i],99844353)
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    items = count.items()
    if len(items) == 1:
        print(0)

    else:
        ans = 1
        tmp = 1
        for i,j in items:
            if i == 0:
                if j >= 2:
                    print(0)
                    return

                tmp = j
                continue

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


        print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
num_d=[0 for i in range(n)]
if d[0]!=0:
  print(0)
  sys.exit()
for i in d:
  if i==0:
    print(0)
    sys.exit()
  num_d[i]+=1
max_d=0
ans=1
for i in range(1,n):
  if num_d[i]!=0:
    if max_d!=i-1:
      print(0)
      sys.exit()
    max_d=i
    ans*=num_d[i-1]**num_d[i]
    ans%=998244353
print(ans)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
from collections import Counter
q=Counter(d)
if d[0]!=0 or q[0]>1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
 
cnt = 1
for i in range(1,max(d)+1):
    ans*=pow(q[i-1],q[i],mod)
print(ans)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
from collections import Counter
q=Counter(d)
if d[0]!=0 or q[0]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=q[i]**q[i+1]
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if d[0] != 0 and d[1] == 0:
    ans = 0
else:
    counter = Counter(d)
    ans = counter[0]
    for i in range(1, max(d) + 1):
        if counter[i] == 0:
            ans = 0
            break
        m, n = counter[i - 1], counter[i]
        c = m ** n
        ans *= c

print(ans % M)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1
if list2[0] != 1:
    print(0)
    exit()
if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]

print(count%998244353)

Submission status: Wrong Answer

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sort_A = sorted(A)
sort_B = sorted(B)

if any(a > b for a, b in zip(sort_A, sort_B)):
    print("No")
    exit()

if any(a < b for a, b in zip(sort_A[1:], sort_B)):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = d[0]
max_d = d[-1]
mod = 998244353

if d[0] == d[1] or d[0] != 0:
    print(0)
    sys.exit()
count = [0 for _ in range(max_d+1)]
for i in range(n):
    count[d[i]] += 1
ans = 1
for i in range(max_d):
    n = count[i]
    m = count[i+1]
    ans *= n**m%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

    d = sorted(d)
    count = Counter(d)
    #print(count)
    #print(len(count))
    #print(count.keys())
    #print(count.items())

    items = count.items()
    if len(items) == 1:
        print(0)

    else:
        ans = 1
        tmp = 1
        for i,j in items:
            if i == 0:
                if j >= 2:
                    ans = 0
                    break
                
                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()))
ans = 1
a = 0
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()
 
prev = 1
for i in range (max(D)):
  if D.count(i+1) == 0:
    if a < N-1:
      print(0)
      exit()
    else:
      print(ans)
      exit()
  else:
    count = D.count(i+1)
    a += count
    ans = ans * pow(prev,count,998244353) 
    prev = count
print(ans)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
from collections import Counter
q=Counter(d)
if d[0]!=0 or q[0]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections
def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = collections.Counter(D)
    count = hash[0]
    if(count != 1):
        print(0)
        return
    for i in range(1, max(D)+1):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
 
for i in range(n):
  LL[L[i]] += 1
  
MOD = 998244353
out = 1
for i in range(len(LL)-1):
  out *= pow(LL[i], LL[i+1], MOD) % MOD
 
if L[0] != 0 or LL[0] != 1:
  out = 0
maximum = max(L)
for i in range(maximum):
  if L[i+1] == 0:
    out = 0
  
print(out)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if d[0] != 0:
    ans = 0
else:
    counter = Counter(d)
    ans = counter[0]
    for i in range(1, max(d) + 1):
        if counter[i] == 0:
            ans = 0
            break
        m, n = counter[i - 1], counter[i]
        c = m ** n
        ans *= c

print(ans % M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections
def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = collections.Counter(D)
    count = hash[0]
    if(count != 0 or count != 1):
        print(0)
        return
    for i in range(1, max(D)+1):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#B:実行時間超過＋不正解
N = int(input())
D_list = [int(s) for s in input().split(" ")]

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

print(res % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
 
for i in range(n):
  LL[L[i]] += 1
  
MOD = 998244353
out = 1
for i in range(len(LL)-1):
  out *= pow(LL[i], LL[i+1], MOD) % MOD
 
if L[0] != 0 or LL[0] != 1:
  out = 0
maximum = max(L)
print(maximum)
for i in range(maximum):
  if L[i+1] == 0:
    out = 0
  
print(out)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
key =0
D = list(map(int,input().split()))
D = sorted(D)
if D[0] != 0:
  key+=1
c = collections.Counter(D)
c = c.most_common()
c.sort(key=lambda x:x[0])
s = 1
key =0
for i in range(len(c)):
  if c[i][0] == 0:
    key += c[i][1]
  else:
    if i == 0:
      pass
    else:
      s *= c[i-1][1]**c[i][1]
if len(c) != c[-1][0]+1:
  key = 0
if key == 1:
  print(s%998244353)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
import sys

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

cnt = collections.Counter(d)

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

p=1

for i in range(1,max(d)+1):
    if  cnt[0]==0:
        print(0)
        sys.exit(0)        
    else:
        p = (p * pow(cnt[i-1], cnt[i], 998244353))%998244353

print(p)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
D_count=sorted(Counter(D).items())
if D_count[0][0]!=0 or D_count[0][1]!=1:print(0);exit()
ans=1
for i in range(1,max(D)+1):
    if D_count[i][0]==i:
        ans *=(D_count[i-1][1]**D_count[i][1])
        ans %=998244353
    else:print(0);exit()
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 = d[0]
max_d = d[-1]
mod = 998244353

if d[0] == d[1] or d[0] != 0:
    print(0)
    sys.exit()
count = [0 for _ in range(max_d+1)]
num = 0
counter = 0
for i in range(n):
    if d[i] == num:
        counter += 1
    else:
        if d[i] == num+1:
            count[num] = counter
            counter = 1
            num += 1
        else:
            print(0)
            sys.exit()
count[-1] = counter
ans = 1
for i in range(max_d):
    n = count[i]
    m = count[i+1]
    ans *= n**m%mod
print(ans)

Submission status: Wrong Answer

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

MOD = 998244353
L = [0]*(n+1)

for a in A : L[a] += 1
#print(L)
  
if A[0] == 1 :
  print(0)
  exit()

zerofirst = L.index(0)
for i in range(n-1,-1,-1) :
  if L[i] != 0 :
    nonzerolast = i
    break

if zerofirst < nonzerolast :
  print(0)
  exit()

ans = 1
for a in L[:nonzerolast+1] :
  ans *= a; ans %= MOD

print(ans)

#print(zerofirst, nonzerolast)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
 
for i in range(n):
  LL[L[i]] += 1
  
MOD = 998244353
out = 1
for i in range(len(LL)-1):
  out *= pow(LL[i], LL[i+1], MOD) % MOD
 
if L[0] != 0 or LL[0] != 1:
  out = 0
maximum = max(L)
for i in range(maximum):
  if L[i] == 0:
    out = 0
  
print(out)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if d[0] != 0:
    ans = 0
else:
    counter = Counter(d)
    ans = 1
    for i in range(max(d) + 1):
        if counter[i] == 0:
            ans = 0
            break
        if counter[i - 1] > 1:
            m, n = counter[i - 1], counter[i]
            c = m ** n
            ans *= c

print(ans % M)

Submission status: Wrong Answer

Solution code:
import math

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

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

dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if dict[key] != 1:
        print(0)
        exit()       
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

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 = Counter(A)
if B[0] == 1:
    ans = 1
    for i in range(max(A)+1):
        ans *= pow(B[i], B[i+1], MOD) % MOD
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import collections
def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = collections.Counter(D)
    count = hash[0]
    for i in range(1, max(D)+1):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    
for key in dict:
    if dict[key] != 0:
        print(0)
        exit()
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Wrong Answer

Solution code:
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for k, v in sorted(c.items()):
        print(k, v)
        if k == 0 or k == 1:
            continue
        elif v == 0:
            return print(0)
        else:
            ans *= c[k-1]**v
            ans = int(ans) % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import factorial
def ncr(n,r):
 a = factorial(n) // factorial(r) // factorial(n - r)
 return a
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def solve():
  n = int(input())
  d = list(int(i) for i in input().split())
  mod = 998244353
  query = [0]*n
  length = 0
  for i in range(n):
    tmp = d[i]
    length = max(tmp,length)
    query[tmp] += 1
  ans = query[0]
  now = ans
  if now == 0:
    print(0)
    exit()
  for i in range(1,length+1):
    next = query[i]
    if next == 0:
      print(0)
      exit()
    if next == 1:
      continue
    if now == 1:
      ans *= next
    else:
      ans *= ncr((next+now-1),now-1)
    ans %= mod
    now = next

  print(ans)
solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
d_array = [int(x) for x in input().split()]
counter = {x: 0 for x in range(-1, 10 ** 5 + 1)}
for i in d_array:
    counter[i] += 1
MOD = 998244353
if d_array[0] != 0:
    print(0)
    exit()
ans = 1
for num in set(d_array):
    if num == 0:
        continue
    if counter[num-1] == 0:
        print(0)
        exit()
    ans *= (counter[num-1])**counter[num]
    ans = ans % MOD
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
D=many_int()

num=998244353


dicts={}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True

if keys[0]!=0:
    flg=True
else:
    if dicts[0]!=1:
        flg=True
        
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d.count(0)!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
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 = []
    d = sorted(d)

    distance = [0] * (N + 1)

    for _d in d:
        distance[_d] += 1

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

    ans = 1
    for i in range(1, (N + 1)):
        n = distance[i-1]
        r = distance[i]
        ans = ans * n ** r
        ans = ans % MOD
        # print(ans)

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

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


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

if c[0]!=1:
    ans=0

# print(c)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
 
mod = 998244353
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 = ((answer % mod) * ((c_i1**c_i2) % mod)) % mod
    
  print(answer%998244353)

Submission status: Wrong Answer

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

a = [0 for _ in range(N)]

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

ans = 0

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

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  else:
    if a[i] == 0:
      if cnt == N:
        break
      else:
        ans = 0
    else:
      temp = a[i-1] ** a[i]
      ans = (ans * temp ) % _mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
 
for i in range(n):
  LL[L[i]] += 1
  
MOD = 998244353
out = 1
for i in range(len(LL)-1):
  out *= pow(i+1, LL[i+1], MOD)
  out = out % MOD
 
if L[0] != 0 or L.count(0) != 1:
  out = 0
print(out)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)
if n==1 or n==2:
	print(lljgs)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if D[0] != 0:
    print(0)
else:
    D = np.sort(D[1:])
    if sum(D == 0) != 0:
        print(0)
    elif sum(np.diff(np.array(list(set(D)))) != 1) != 0:
        print(0)
    else:
        print(np.prod(D) % 998244353)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(len(list2)):
    count *= list2[i-1]**list2[i]

print(count%998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
d=list(map(int,input().split()))
count=1
if d[0]!=0:
    count=0
for i in range(max(d)):
    count *= pow(i+1,d.count(i+1),99844353)
print(count)

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 = []
    d = sorted(d)

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

    distance = [0] * N

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

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

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

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

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

check = 0
if not check == D[0]:
    print(0)
    sys.exit()
countl = [0]
for d in D:
    if not check == d:
        check += 1
        countl.append(0)
        if not check == d:
            print(0)
            sys.exit()
    countl[-1] += 1
if not countl[0] == 1:
    print(0)
    sys.exit()

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

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
	else:
		print(2/0) #
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=pow(p[i],p[i+1],mod)
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict

def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = defaultdict(int)
    for i in D:
        hash[i] += 1
    count = hash[0]
    for i in range(1, n):
        count *= hash[i-1] ** hash[i]
    print(count%998244353)
    
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 d[0] != 0:
    print(0)
    exit()

mod = 998244353

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 = -1
check = 1

for i in list_d:

    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = (ans * (check**cnt))%mod
    check = cnt
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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


dict = {}

for i in range(len(D)):
    if D[i] not in dict:
        dict[D[i]] = 1
    else:
        dict[D[i]] += 1

for i in range(max(D)):
    if i not in dict:
        dict[i] = 0
    

for key in dict:
    if key == 0:
        break
    if dict[key] == 0:
        print(0)
        exit()
sum = 1
n = 0

#dict = list(sorted(dict.items(), key=lambda x:x[0]))
dict_dm = sorted(dict)
#print(dict)
#print(dict_dm)
flg = 0
for i in range(len(dict_dm)):
    if i == 1:
        #print("check2")
        n = dict[i]
    elif i >=1:
        #print("check1")
        sum = (sum * n**dict[i])%998244353
        n = dict[i]

print(sum%998244353)

Submission status: Wrong Answer

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


list2 = [0]*(max(list1)+1)
for i in range(len(list1)):
    list2[list1[i]] += 1

if 0 in list2:
    print(0)
    exit()
count = 1
for i in range(1,len(list2)):
    count *= list2[i-1]**list2[i]
if list2[-2] == 1:
    count *= list2[-1]
print(count%998244353)

Submission status: Wrong Answer

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

a = [0 for _ in range(N)]

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

ans = 0

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

cnt = 0
for i in range(N):
  cnt += a[i]
  if i == 0:
    ans = 1
  elif a[i] == 0:
    break
  else:
    temp = a[i-1] ** a[i]
    ans = (ans * temp ) % _mod

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 = []
    d = sorted(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 or distance[0] != 1:
        print(0)
        return

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

    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
d=list(map(int,input().split()))
count=1
if d[0]!=0:
    count=0
for i in range(max(d)):
    count *= ((i+1) ** d.count(i+1))
    count = count%99844353
print(count)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
#print(num)
ans=1
for i in range(1, max(d)+1):
    #print(num[i-1]**num[i])
    #ans = ans * pow(num[i-1], num[i], 998244353)%998244353
    ans*=num[i-1]**num[i]

if d[0]!=0 or d.count(0)!=1:
    print(0)
else:
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict

def main():
    n = int(stdin.readline().rstrip())
    D = [int(i) for i in input().split()]
    hash = defaultdict(int)
    for i in D:
        hash[i] += 1
    count = hash[0]
    for i in range(1, n):
        count *= hash[i-1] ** hash[i]
    print(count)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
if D[0]!=0:
    print(0)
else:
    D.sort()
    num_list = []
    cnt=1
    n=0
    for j in range(1,N):
        if D[j]==n:
            cnt+=1
            if j==N-1:
                num_list.append(cnt)
        else:
            num_list.append(cnt)
            cnt=1
            n+=1
            if j==N-1:
                num_list.append(1)
    if num_list[0]!=1:
        print(0)
    else:
        len_list = len(num_list)
        if len_list==1:
            print(1)
        elif len_list==2:
            print(1)
        else:
            S=1
            for m in range(1,len_list-1):
                S = S*(num_list[m]**num_list[m+1])
            print(S%998244353)