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 Counter


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


if __name__ == '__main__':
    resolve()

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)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
if l1[0]!=0:
  print(0)
else:
  ld=[0 for i in range(n)]
  for i in range(n):
    ld[l[i]]+=1
  if ld[0]!=1:
    print(0)
  else:
    ans=1
    b=True
    index=n-1
    for i in range(1,1+n):
      if ld[-i]!=0 and b:
        index=n-i
        b=False
    for i in range(1,index+1):
      if ld[i]==0:
        ans=0
      else:
        ans*=(ld[i-1]**ld[i])%(998244353)
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations


def li ():
	return list (map (int, sys.stdin.readline ().split ()))


def num ():
	return map (int, sys.stdin.readline ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


def lcm ( x, y ):
	gg = find_gcd (x, y)
	return (x * y // gg)



mm = 998244353
def solve ():
	t = 1
	for tt in range (t):
		n=nu()
		a=li()
		a.sort()
		if(a[0]!=0):
			print(0)
		else:
			ox=[]
			cc=1
			las=a[0]
			for i in range(1,n):
				if(las==a[i]):
					cc+=1
				else:
					ox.append((las,cc))
					cc=1
					las=a[i]
			ox.append ((las, cc))
			if(ox[0][1]!=1):
				print(0)
			last=ox[0][1]
			next=ox[0][0]+1
			ans=1
			for i in range(1,len(ox)):
				if(next!=ox[i][0]):
					ans=0
				ans=(ans*pow(last,ox[i][1],mm))%mm
				last=ox[i][1]
				next+=1
			print(ans)










if __name__ == "__main__":
	solve ()

Submission status: Wrong Answer

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
tree = [(D[i], i) for i in range(N)]
tree.sort(key=lambda x: x[0])

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

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

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

print(ans)

Submission status: Wrong Answer

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

ct = Counter(Ds)
M = max(ct)
if ct[0] != 1:
    print(0)
    exit()
ans = 1
last = 1
for i in range(1, M+1):
    if ct[i] == 0:
        print(0)
        exit()
    ans *= last ** ct[i]
    ans %= MOD
    last = ct[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=1

zeros=0
for i in a:
    if i==0:
        zeros+=1
    else:
        ans*=i
    ans = ans % 998244353

if zeros!=1:
    print(0)
    quit()

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
D = {i:[] for i in range(max(d)+1)}
for i in range(n):
  if i == 0 and d[i] != 0:
    print(0)
    exit()
  if i != 0 and d[i] == 0:
    continue
  D[d[i]] += [i]
ans = 1

for i in range(max(d)):
  ans *= (len(D[i]) ** len(D[i+1])) % 998244353

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()
    for i in range(len(di)-1):
        if di[i][0] != di[i + 1][0] - 1:
            # print(di[i][0],di[i+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:
# -*- coding: utf-8 -*-
from collections import Counter 
import sys

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

mod = 998244353

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
NUMBER = 998244353

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

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
D.sort()
ans = [1]
hoge = 1
if D[0] != 0 or (N >= 2 and D[1] == 0):
    print(0)
    exit()
for i in range(1,N):
    if D[i] == D[i-1]:
        hoge += 1
    elif D[i] == D[i-1]+1:
        ans.append(hoge)
        hoge = 1
    else:
        print(0)
        exit()
ans.append(hoge)
ret = 1
for i in range(len(ans)-1):
    ret *= pow(ans[i],ans[i+1],MOD)
    ret %= MOD
print(ret)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial
from collections import Counter

def nHr(n, r):
    return factorial(n + r -1) // factorial(r)  // factorial(n-1)

n = int(input())
d_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(d_ls)
res = 1
if d_ls[0] != 0:
    print(0)
else:
    for i, count in sorted(ct.items(), key=lambda x:x[1]):
        if i == 0:
            continue
        res *= ct[i-1] ** count % 998244353
    print(res)

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]
print(ans)

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:
N = int(input())
D = sorted(list(map(int, input().split())))
if D[0] != 0:
  print(0)
Dn = [ D.count(n) for n in range(0, max(D) + 1) ]
n = 1
for i, Di in enumerate(Dn):
	if i == 0 :
		continue
	else:
		n = (n * (1 if Dn[i - 1] == 1 else Dn[i - 1]**Di)) % 998244353
print(n)

Submission status: Wrong Answer

Solution code:
import collections

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

max_nums = max(nums)
cnt_list = collections.Counter(nums)
#print(cnt_list)

ans = 1
if cnt_list[0] == 1 and nums[0] == 0:
	for i in range(1, max_nums + 1):
		if cnt_list[i] == 0:
			print(0)
			break
		else:
			ans *= (cnt_list[i - 1] ** cnt_list[i]) % 998244353
			#print(ans)
	print(ans % 998244353)

else:
	print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=sorted(map(int,input().split()))
from collections import defaultdict
d=defaultdict(int)
for e in D:
    d[e]+=1
s,x,r=1,1,1
m=998244353
if D[0]!=0 or d[0]!=1:
    r=0
while s<N:
    r*=pow(d[x-1],d[x],m)
    s+=d[x]
    x+=1
print(r%m)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def power_func(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()))
if d[0] != 0:
    print(0)
    exit(0)
d = Counter(sorted(d))
prev_count = 1
prev_index = -1
MOD = 998244353
ans = 1
for k, v in d.items():
    if k != prev_index+1:
        print(0)
        exit(0)
    ans *= power_func(prev_count, v, MOD)
    ans %= MOD
    prev_index = k
    prev_count = v
print(ans)

Submission status: Wrong Answer

Solution code:
from itertools import groupby
N = int(input())
D = groupby(sorted(list(map(int, input().split()))))
t = 998244353

ans = 1
pre = 0
cur = 0
for i, d in D:
    if i != cur:
        print(0)
        exit()
    else:
        cur += 1
    l = len(list(d))
    if i <= 1:
        pre = l
        continue
    ans = (ans * (pre**l)) % t
    pre = l

print(ans % t)

Submission status: Wrong Answer

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

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

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

if c[0]>1:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
*D, = map(int, input().split())
D = sorted(D)
levels = [0 for _ in range(D[-1]+1)]
for d in D:
    levels[d] += 1
if 0 in levels: print(0)
else:
    ans = 1
    for l1, l2 in zip(levels, levels[1:]):
        ans *= pow(l1, l2, MOD)
        ans % MOD
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
d = defaultdict(int)
m = 0
for i in a:
    d[i] += 1
    m = max(m,i)
res = 1
tmp = 1
for i in range(m+1):
    if i == 0:
        if d[i] != 1:
            print(0)
            quit()
        continue
    if d[i] == 0:
        res = 0
        break
    if i == 1:
        tmp = d[i]
        continue
    res = (res * tmp ** d[i] )%998244353
    tmp = d[i]
print(res%998244353)

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
	Datas, Cnts = [A[0]], [1]
	index = 0
	for i in range(1, len(A)):
		if A[i] == Datas[index]:
			Cnts[index] += 1
		else:
			Datas.append(A[i])
			Cnts.append(1)
			index += 1
	return Datas, Cnts

def zero_end():
    print(0)
    exit()


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

D_data, D_count = ContinueCnt(D)

INF = 998244353

# first check zero
if D.count(0) != 1:
    zero_end()

ans = 1

# check 1 ~ max(D)
for i in range(1, max(D_data) + 1):
    if i not in D_data:
        zero_end()
    else:
        ans *= D_count[i - 1] ** D_count[i]
        ans %= INF
        # print("now = ", ans)  # for debug

print(ans % INF)

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:
N = int(input())
from collections import Counter
c = Counter([int(i) for i in input().split()])

if c[0] != 1:
  print(0)
  quit()
if len(c.keys()) != max(c.keys())+1:
  print(0)
  quit()

  
res = 1
for i in range(1,1+max(c.keys())):
  res *= c[i-1]**c[i]
  res %= 998244353
print(res)

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

# a = comb(n, r)

# import pow

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 998244353
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ds = LI()
    c = Counter(ds)
    max_ = max(ds)
    ans = 1
    before = 1
    for i in range(max_ + 1):
        if i not in c:
            print(0)
            return
        now = c.get(i)
        ans *= pow(before, now, MOD)
        # ans = ans % MOD
        before = now
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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]
    print(a)

Submission status: Wrong Answer

Solution code:
INFTY = 998244353
N = int(input())
D = list(map(int,input().split()))
C = {}
for i in range(N):
    d = D[i]
    if d not in C:
        C[d] = 0
    C[d] += 1
k = len(C)
flag = 0
for i in range(k):
    if i not in C:
        cnt = 0
        flag = 1
        break
if flag==1:
    cnt = 0
else:
    cnt = 1
    for i in range(1,k-1):
        cnt = (cnt*(C[i]**C[i+1]))%INFTY
print(cnt)

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

mod=998244353

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

    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

def main():
    N=int(input())
    if N==0:
        return 0
    DL=[int(x) for x in input().split()]
    if DL[0]!=0:
        return 0
    
    
    dic=collections.Counter(DL)
    if dic[0]!=1:
        return 0
    keys=dic.keys()
    result=1
    for i in range(1,max(keys)+1):
        if dic[i]==0 and dic[i-1]==0:
            return 0
        result*=dic[i-1]**dic[i]

    return result


print(main())

Submission status: Wrong Answer

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

mv = max(a)

xs = [0] * (mv+1)
for y in a:
    xs[y] += 1

#print(xs)

if xs[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(len(xs)-1):
        ans *= xs[i] ** xs[i+1]
        ans %= 998244353

    print(ans)

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

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial
from collections import Counter

def nHr(n, r):
    return factorial(n + r -1) // factorial(r)  // factorial(n-1)

n = int(input())
d_ls = [int(i) for i in sys.stdin.readline().split()]
ct = Counter(d_ls)
res = 1
if d_ls[0] != 0:
    print(0)
else:
    for i, count in sorted(ct.items(), key=lambda x:x[1]):
        if i == 0:
            continue
        res *= ct[i-1] ** count
    print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
ans = 1
if 0 in d:
    d.remove(0)
for i in d:
    ans *= i
if ans == 1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

# fact(int)
def fact(n):
  if(n == 1):
    return 1
  else:
    return (n * fact(n - 1))

# gcd(int,int)
def gcd(a,b):
  if a == 0:
    return b
  elif b == 0:
    return a
  else:
    return gcd(b,a % b)

# lcm(int,int)
def lcm(a,b):
  return (a * b / gcd(a,b))

# qsort(array[])
def qsort(seq):
  if len(seq) < 1:
      return seq
  pivot = seq[0]
  left = []
  right = []
  for x in range(1, len(seq)):
    if seq[x] <= pivot:
        left.append(seq[x])
    else:
        right.append(seq[x])
  left = qsort(left)
  right = qsort(right)
  foo = [pivot]
  return (left + foo + right)

# = map(int, input().split())
# = int(input())
# = raw_input().split()
# = list(int(i) for i in input().split())

n = int(input())
d = list(int(i) for i in input().split())

ans = 1
if d[0] == 1:
  print('0')
else:
  ds = sorted(d)
  for i in range(1, n):
    ans *= d[i]
  
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=sorted(list(map(int,input().split())))
if d[0]!=0:
    print(0)
else:
    c=Counter(d)
    c_v=list(c.values())
    ans=1
    for i in range(1,len(c_v)):
        ans*=c_v[i-1]**c_v[i]
        ans%=998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
d = defaultdict(int)
m = 0
for i in a:
    d[i] += 1
    m = max(m,i)
res = 1
tmp = 1
for i in range(m+1):
    if i == 0:
        if d[i] != 1:
            print(0)
            quit()
        continue
    if d[i] == 0:
        res = 0
        break
    if i == 1:
        tmp = d[i]
        continue
    res = (res * tmp ** d[i] )%998244353
    tmp = d[i]
print(res)

Submission status: Wrong Answer

Solution code:
INF = 998244353

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

p = [0]*(n+10)
for i in range(n):
    p[d[i]]+=1
ans = 1
for i in range(1,n):
    if p[i]==0:
        break

    if p[i-1]==0:
        print(0)
        exit()

    ans = ans*(p[i-1]**p[i])
    ans = ans%INF
ans = ans%INF
print(ans)

Submission status: Wrong Answer

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

from collections import defaultdict
d = defaultdict(int)

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

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

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 not in count:
        answer = 0
        break
    answer *= prev ** count[i]
    prev = count[i]
print(answer % 998244353)

Submission status: Wrong Answer

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

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

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

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


print(ans % 998244353)

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

if max(D_list) + 1 != 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:
import collections
N = int(input())
D_list = list(map(int, input().split()))
mod = 998244353
ans = 1

count_dir = collections.Counter(D_list)
for i in range(max(D_list) + 1):
    if i not in D_list:
        ans = 0
        break
    if i >= 2:
        ans *= count_dir[i-1]**count_dir[i]

if D_list[0] != 0 or count_dir[0] >= 2:
    ans = 0

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+1)
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
#    print(i,c,ans,cnt)    
        
print(ans)

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()
for i in range(1, n):
    if d[i] == 0:
        print(0)
        exit()

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

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

# a = comb(n, r)

# import pow

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ds = LI()
    c = Counter(ds)
    max_ = max(ds)
    ans = 1
    before = 1
    for i in range(max_ + 1):
        if i not in c:
            print(0)
            return
        now = c.get(i)
        ans *= pow(before, now, MOD)
        # ans = ans % MOD
        before = now
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
D = [int(x) for x in input().split()]
if D[0] != 0:
    print(0)
    sys.exit()

ans = 1
for i in range(1, N):
    ans = (ans * D[i]) % 998244353
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)

Submission status: Wrong Answer

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

import sys
mod = 998244353
n = int(input())
dl = list(map(int,input().split()))

if dl[0] != 0:
    print(0)
    sys.exit()
dl = sorted(dl)
before = 0
for i in dl:
    if i - before > 1:
        print(0)
        sys.exit()
    before = i
    

ans = 1
before_e = 1
now_e = 0
now = 0

for d in dl:
    if now != d:
        if now_e == 0:
            print(0)
            sys.exit()
        before_e = now_e
        now_e = 0
        now += 1
    now_e += 1
    ans *= before_e
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
D.sort()
ans = [1]
hoge = 1
if D[0] != 0:
    print(0)
    exit()
for i in range(1,N):
    if D[i] == D[i-1]:
        hoge += 1
    elif D[i] == D[i-1]+1:
        ans.append(hoge)
        hoge = 1
    else:
        print(0)
        exit()
ans.append(hoge)
ret = 1
for i in range(len(ans)-1):
    ret *= pow(ans[i],ans[i+1],MOD)
    ret %= MOD
print(ret)

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(2, 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:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
d = defaultdict(int)
m = 0
for i in a:
    d[i] += 1
    m = max(m,i)
res = 1
tmp = 1
for i in range(m+1):
    if i == 0:
        if d[i] != 1:
            print(0)
            quit()
        continue
    if d[i] == 0:
        res = 0
        break
    if i == 1:
        tmp = d[i]
        continue
    res = (res * tmp ** d[i] )%99824453
    tmp = d[i]
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
if l1[0]!=0:
  print(0)
else:
  ld=[0 for i in range(n)]
  for i in range(n):
    ld[l[i]]+=1
  if ld[0]!=1:
    print(0)
  else:
    ans=1
    b=True
    index=n-1
    for i in range(1,1+n):
      if ld[-i]!=0 and b:
        index=n-i
        b=False
    for i in range(1,index+1):
      if ld[i]==0:
        ans=0
      else:
        ans*=ld[i-1]**ld[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
MOD = 998244353

MAX_N = 10**5

fac = [1] + [0] * MAX_N
for i in range(1, MAX_N+1):
    fac[i] = fac[i-1] * (i) % MOD

fac_inv = [1] + [0] * MAX_N
# Fmrmat's little theorem says a**(p-1) mod p == 1
# then, a * a**(p-2) mod p == 1
# it means that a**(p-2) is the inverse element
# Here, Get 1 / n! first
fac_inv[MAX_N] = pow(fac[MAX_N], MOD-2, MOD)
for i in range(MAX_N, 1, -1):
    fac_inv[i-1] = fac_inv[i] * i % MOD

def mod_nCr(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD

n = int(input())
d = [int(item) for item in input().split()]
max_val = max(d)
cnt = [0] * (max_val + 1)
for item in d:
    cnt[item] += 1

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

ans = 1
for a, b in zip(cnt, cnt[1:]):
    ans *= pow(a, b, MOD)
    ans %= MOD
print(ans)

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

Submission status: Wrong Answer

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time

setrecursionlimit(10**6)
input=stdin.readline

n=int(input())
d=[int(i) for i in input().split()]
if d[0]!=0:
    print(0)
    exit()
dst=[0]*(10**5+1)
ans=1
for i in d: dst[i]+=1

if dst[0]>1:
    print(0)
    exit()
for i in range(2,max(d)+1):
    if dst[i]==0:
        print(0)
        exit()
    ans*=dst[i-1]**dst[i]
print(ans)