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 fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res



def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = list(set(a))
    d = Counter(a)
    if a[0] != 0:
        print(0)
    else:
        ans = 1
        for i in range(1, len(s)):
            if d[s[i] - 1] == 0 and s[i] > 0:
                print(0)
                exit()
            ans = (ans * modpow(d[s[i - 1]], d[s[i]], 998244353)) % 998244353
        print(ans)
            

    
    

        
        
        
            

    
   


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ans=1
for i in range(max_d):
    ans*=c[i] ** c[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

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

if li[0] != 0:
    print(0)
    exit()
point = 1
for i in range(1,len(li)):
    point *= li[i]
print(point)

Submission status: Wrong Answer

Solution code:
m = 998244353
def myPow(a,b):
    a %= m
    if b == 1:
        return a%m
    elif b == 0:
        return 1
    if b%2 == 0:
        return myPow(a**2,b//2)%m
    else:
        return (a%m)*myPow(a**2,(b-1)//2)%m

n = int(input())
ngo = [0]*n
d = list(map(int,input().split()))
for i in range(n):
    ngo[d[i]]+=1
if ngo[0] != 1:
    print(0)
    exit(0)
ans = 1
for i in range(n-1):
    ans = (ans*myPow(ngo[i],ngo[i+1])%m)%m
print(ans%m)

Submission status: Wrong Answer

Solution code:
import collections

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

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

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

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
	print(0)
	exit()
if n==1:
	print(1)
	exit()
d.sort()
if d[1]==0:
	print(0)
	exit()
p=[]
cnt=1
for i in range(1,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*=p[i]**p[i+1]
	ans%=mod
print(ans)

Submission status: Wrong Answer

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


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


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

Submission status: Wrong Answer

Solution code:
n= int(input())
d= sorted(list(map(int, input().split())))
x=[0]*(d[n-1]+1)
k=0
ans=False
for i in range(n):
    if d[i]==k:
        x[k]+=1
    elif d[i]==k+1:
        k+=1
        x[k]+=1
    else:
        ans=True
    #print(ans)
#print(d)
#print(x)
if ans or x[0]>=2:
    print(0)
else:
    a=1
    for i in range(d[n-1]):
        a*=x[i]**x[i+1]%998244353
    print(a)

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

c = sorted(Counter(d).items())
ans = 1

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
mod=998244353

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

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

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

Submission status: Wrong Answer

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

L = [0] * (max(D) + 1)
for d in D:
    L[d] += 1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d_list = [int(i) for i in input().split()]
R_max = max(d_list)+1
R = [0] * R_max
ans = 1

for di in d_list:
  R[di] += 1
  
if R[0] == 0:
  print(0)
  exit()
  
for i in range(1, R_max):
  ans *= R[i-1]**R[i]%998244353
print(ans%998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
d = list(Counter(d).items())
if d[0][0] != 0:
    print(0)
    quit()
elif d[0][0] == 0 and d[0][1] > 1:
    print(0)
    quit()

n = len(d)
ans = 1
for i in range(1,n):
    j,k = d[i]
    l,m = d[i-1]
    if j != l+1:
        print(0)
        quit()
    ans *= m**k
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import heapq
mod = 998244353
n = int(input())
d = map(int, input().split())
q = []
for x in d:
  heapq.heappush(q, x)
prev = -1
x = 0
y = 1
ans = 1
for i in range(n):
  a = heapq.heappop(q)
  if a == prev:
    x += 1
  elif a == prev + 1:
    x += 1
    ans = ans * (y ** x) % mod
    y = x
    x = 0
  else:
    print(0)
    break
  prev = a
else:
  x += 1
  ans = ans * (y ** x) % mod
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
e = collections.Counter(d)
if d[0] != 0:
    print(0)
    exit()

cntsum = 1
judge_cnt = 0

if e[1] == 0:
    print(0)
    exit()
for i in range(1, n + 1):
    if i == 1:
        pass
    else:
        cntsum *= e[i - 1] ** e[i]
print(cntsum)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
  print(0)
else:
  del d[0]
  d.sort()
  c = collections.Counter(d)
  ll = len(c)
  ans = 1
  for i in range(1, ll+1):
    if c[i] == 0:
      print(0)
      break
    else:
      ans *= i**c[i]
  print(ans)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = []
for i in range(max(D)+1):
    D_.append(D.count(i))
ans = 1
def m(i,j):
    return i ** j

if N == 1:
    print(1)
else:
    for k in range(len(D_)-1):
        ans *= m(D_[k],D_[k+1])
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if c != 1:
    print(0)
else:
    count = 1
    for i in d[1:][::-1]:
        if i == 1:
            break
        count *= i % mod
    print(count % mod)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
    exit()
D.sort()
d = {}
for i in range(D[-1] + 1):
    d[i] = 0
for i in D:
    d[i] += 1
if d[0] != 1:
    print(0)
    exit()
for i in range(1, D[-1] + 1):
    if d[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(2, D[-1] + 1):
    ans *= d[i-1]**d[i]
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
maximum = max(L)
  
  
out = 1
for i in range(maximum):
  out *= pow(i+1, LL[i+1])

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

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

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
A = list(map(int, input().split()))
u = 998244353

if A[0]!=0:
    print(0)
    exit()
dp = {}

for i in range(1,N):
    d = A[i]
    if d in dp:
        dp[d] +=1
    else:
        dp[d] = 1

M = max(A)
ans = 1
for i in range(1,M+1):
    if not i in dp:
        print(0)
        exit()
    k = dp[i]
    if i==1:
        pre = k
    else:
        now = pre**k
        ans *= now
        ans %= u
    pre = k
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import dropwhile

n = int(input())
D = list(map(int, input().split()))
DIV = 998244353

dist = [0]*n

for i in D:
    dist[i] += 1

dist.reverse()
ddist = list(dropwhile(lambda x: x == 0, dist))
ddist.reverse()

ans = 1
for i in range(len(ddist) - 1):
    ans *= ddist[i] ** ddist[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]

max_B = -1
for i in range(1, len(A)):
    B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

ans = 1
for i in range(1, max_B):
    if A[0] != 0:
        ans = 0 
        break
        
    elif B[i] == 0:
        ans = 0 
        break
    else:
        ans *= B[i-1] ** B[i]

print(ans)

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

if D[0] != 0 or a[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, N):
        ans = ans * pow(a[i - 1], a[i], MOD)
        # print(ans)
        # ans = pow(ans, max(a[i] * D[i - 1], 1), MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
aset = list(set(a[1:]))
a.sort()
aset.sort()


if N == 1:
  if a[0] == 0:
    print(1)
  else:
    print(0)
else:
  if a[0] == 0:
    tmp = 1
    for i in aset:
      if tmp == i:
        tmp += 1
      else:
        print(0)
        exit()

    ans = 1
    for i in range(1, N):
      ans = ans*a[i] %mod
    print(ans)
  else:
    print(0)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

input = raw_input
range = xrange
M = 998244353

def main():
    N = int(input())
    Ds = list(map(int, input().split(" ")))
    counter = collections.Counter(Ds)
    depths = counter.keys()
    
    min_depth = min(depths)
    max_depth = max(depths)

    if min_depth != 0:
        #print("test1")
        return 0
    
    if len(depths) != max_depth + 1:
        #print("test2")
        return 0

    out = 1
    for depth in range(1, max_depth+1):
        num = counter[depth]
        if depth >= 2:
            for i in range(num):
                out = out * before_num
                out = out % M
        before_num = num

    return out

out = main()
print(out)

Submission status: Wrong Answer

Solution code:
from collections import Counter 

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

answer = 1
prev = 1
count = Counter(D)
for i in range(max(count.keys()) + 1):
    if i == 0 and count[i] != 1:
        answer = 0
        break
    if i not in count:
        answer = 0
        break
    answer *= prev ** count[i]
    prev = count[i]
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
mod=998244353
ans=1
n=int(input())
d=list(map(int,input().split()))
c=collections.Counter(d)
num=list(c.values())
if d[0]!=0 or num[0]!=1:
  print(0)
else:
  for i in range(1,len(num)-1):
    ans*=(num[i]**num[i+1])%mod
print(ans%mod)

Submission status: Wrong Answer

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

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

    arr1.sort()

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

    print(ways)
         

main()

Submission status: Wrong Answer

Solution code:
def f_b():
    n, *d = map(int, open(0).read().split())
    c = [0]*(max(d)+1)
    for i in range(n):
        c[d[i]] += 1

    a = 1
    for i in range(1, len(c)):
        a *= c[i-1]**c[i]

    print(a)

if __name__ == "__main__":
    f_b()

Submission status: Wrong Answer

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

if c[0] != 1:
	print(0)
	exit()
flag = True
for i in range(N):
	if not flag and c[i] > 0:
		print(0)
		exit()
	if c[i] == 0:
		flag = False

if c[2] == 0:
	print(1)

ans = 1
for i in range(1, N):
	if c[i] == 0:
		print(ans)
		exit()
	t = (c[i-1] ** c[i]) % MOD
	ans = (ans * t) % 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)
counter=sorted(c.items(), key=lambda x:x[0])
if D[0]!=0 or counter[0][1]>1:
  print(0)
else:
  ans=1
  for i in range(2, len(counter)):
    for j in range(counter[i][1]):
      ans=(ans*counter[i-1][1])%MOD
    #ans=(ans*(counter[i-1][1]**counter[i][1])%MOD)%MOD
  print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#NIKEI B
import sys
import math
import collections
#sys.setrecursionlimit(100000)


n=int(input())

tmp = input().split()
d = list(map(lambda a: int(a), tmp))

max=0
numlist={}
for i in range(0,n):
	if(d[i]>max):
		max=d[i]
	if(d[i] in numlist):
		numlist[d[i]]+=1
	else:
		numlist[d[i]]=1


if(d[0]!=0):
	print(0)
	sys.exit()
for i in range(max):
	if not(i in numlist):
		print(0)
		sys.exit()

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

#ans %= 998244353
#print(ans)
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float('INF')

#A
def A():
    n = II()
    n -= 1
    print(n // 2)
    return

#B
def combination_mod(n, k, mod=mod):
    """ power_funcを用いて(nCk) mod p を求める """ 
    """ nCk = n!/((n-k)!k!)を使用 """

    from math import factorial
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    a = factorial(n) % mod
    b = factorial(k) % mod
    c = factorial(n - k) % mod
    return (a * pow(b, mod - 2, mod) * pow(c, mod - 2, mod)) % mod
    

def B():
    n = II()
    d = LI()
    dic = defaultdict(int)
    if d[0] != 0:
        print(0)
        return
    for di in d[1:]:
        dic[di] += 1
    ans = 1
    di = list(dic.items())
    di.sort()
    if di[0][0] != 1:
        print(0)
        return
    for i in range(len(di) - 1):
        if di[i][0] != di[i + 1][0] - 1:
            print(0)
            return
    be = 1
    for _, b in di:
        ans *= pow(be, b, mod)
        be = b
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

cnt = collections.Counter(d)
total = 1
p = 1
for i in range(1, n):
    if p == 0 and cnt[i] > 0:
        print(0)
        exit()
    total *= p**cnt[i]
    total %= mod
    p = cnt[i]
print(total % mod)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
dc = collections.Counter(d).most_common()
dc = sorted(dc)
count = 0
ans = 1
last = 1
for i in dc:
    if i[0] == count:
        ans *= last ** i[1]
        last = i[1]
        count += 1
    else:
        print(0)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

num = 998244353

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

D.sort()
D_cnt = dict(Counter(D))
D_list = list(D_cnt)

ans = 1
# print(D_list == list(range(len(D_list))))
# print(list(range(len(D_list))))
if D_list != list(range(len(D_list))):
    print(0)
    exit()

for i in range(1, len(D_list)- 1):
    n = D_cnt[i]
    m = D_cnt[i + 1]
    ans *= (n ** m)
    ans %= num
print(ans % num)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

    dic = defaultdict(int)

    for d in d_s:
        dic[d] += 1

    t_s = sorted(dic.items())
    
    ans = 1

    pre_n = -1
    pre_count = 1

    for t in t_s:
        if t[0] - 1 != pre_n:
            print(0)
            quit()
        ans *= pre_count ** t[1]
        pre_n += 1
        pre_count = t[1]
    print(ans % 998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

a = [0] * n
for i in range(n):
    a[d[i]] += 1

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            print(0)
            exit()
    else:
        if a[i] > 0:
            if a[i-1] == 0:
                print(0)
                exit()
            else:
                ans *= pow(a[i-1], a[i], MOD)
                ans = ans % MOD
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
    
print(ans)

Submission status: Wrong Answer

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

setrecursionlimit(1000000)

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

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

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

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

	return arr

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

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

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

	return True

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

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

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

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

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

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

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

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
max_d=max(d)
ans=1
for i in range(max_d):
    ans*=d.count(i) ** d.count(i+1)
print(ans)

Submission status: Wrong Answer

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

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
#b = [int(i) for i in readline().split()]

wt = [0]*(n+2)
for i in a:
    wt[i] += 1

MOD = 998244353

ans = 1
cnt = 1

#print(wt)
for i,c in enumerate(wt):
    if i == 0:
        if c != 1:
            ans = 0
            break
        else: pass
    else:
        cnt += c
#        print(cnt,c)
        if cnt != n:
            if c == 0:
                ans = 0
                break
            else:
                ans *= pow(wt[i-1],c,MOD)
        else:
            ans *= pow(wt[i-1],c,MOD)
            break
    ans %= MOD    
#    print(i,c,ans,cnt)    
        
print(ans%MOD)

Submission status: Wrong Answer

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

import collections
def counter_list(A):
  counter = collections.Counter(A)
  counter =  [list(e) for e in counter.items()]
  counter.sort() #sortしたい場合はつける
  return counter

if(D[0] != 0): ans = 0
else: 
  D = counter_list(D)
  ans = 1
  for i in range(len(D)-1):
    if(i>=1):
      a = D[i][1]%998244353
      b = D[i+1][1]
      ans = ans%998244353
      ans = ans*(a**b)
      ans = ans%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res



def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = list(set(a))
    d = Counter(a)
    if a[0] != 0:
        print(0)
    else:
        ans = 1
        for i in range(2, len(s)):
            if d[s[i] - 1] == 0:
                print(0)
                exit()
            ans = (ans * modpow(d[s[i - 1]], d[s[i]], 998244353)) % 998244353
        print(ans)
            

    
    

        
        
        
            

    
   


if __name__ == '__main__':
    main()

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()))
dmax = max(D)

if D[0]!=0:
	ans = 0
else:
	D = Counter(D)

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
c=0
a = list(map(int,input().split()))
a.sort()
mem = {}
mem['-1']=1
count = 1
for v in a:
    need = v-1
    if str(need) in mem:
        count *= mem.get(str(need))
        count %=mod
    else:
        count = 0
        break
    if str(v) in mem:
        mem[str(v)] = mem.get(str(v))+1
    else:
        mem[str(v)] = 1
print(count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n=int(input())
D=list(map(int,input().split()))
ans=1
data=[0]*(10**5)
M=0
for i in range(n):
    data[D[i]]+=1
    M=max(M,D[i])

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

if D[0]!=0:
    ans=0
if data[0]>=2:
    ans=0
for i in range(M):
    if data[i] ==0:
        ans=0

print(ans)
# print(data[:20])

Submission status: Wrong Answer

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

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


d.sort()
c = collections.Counter(d)
ans = 1
for i in range(len(c)-1):
    x = c[i] ** c[i+1]
    ans *= x
    ans = ans % 998244353


print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
D.sort()
ans = 1
for d in D[1:]:
    ans *= d
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
mod=998244353
if d[0]!=0:
    print(0)
    sys.exit()
d.sort()
if d[1]==0:
    print(0)
    sys.exit()
else:
    lst=[0]*(n+1)
    for i in range(1,n):
        lst[d[i]]+=1
    ans=1
    for i in range(2,d[-1]+1):
        ans*=pow(lst[i-1],lst[i],mod)
    print(ans)