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()))
ans = 0
if not D[0] == 0 or not D.count(0) == 1:
    print(0)
else:
    ans = 1
    for i in range(2, max(D)+1):
        ans = ans * (D.count(i-1)**D.count(i))
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    ans = 1
    for i in range(len(C) -1):
        if C[i] == 0:
            ans = 0
            break
        ans *= C[i] ** C[i+1]
        if ans >= 998244353:
            ans = ans % 998244353
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

setD = list(set(d))
setD.sort()
ans = 1
nodeMulti = 1

if d[0] > 0:
        print(0)
        exit()
else:
        c = Counter(d)
        # for s in setD:
        #         ans *= math.factorial(c[s])
        #         nodeMulti *= c[s]
        # nodeMulti //= setD[-1]

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

        print(ans%998244353)

Submission status: Wrong Answer

Solution code:
mod = 998244353

N = int(input())

nums = [int(x) for x in input().split(' ')]
if nums[0] != 0:
	print(0)
	exit()
	
nums.sort()
#print('yeah')

if N > 1 and nums[1] != 1:
	print(0)
	exit()
	
if N == 1:
	print(1)
	exit()
	


def pow_mod(m,n):
	prod = 1
	for i in range(n):
		prod = (m * prod) % mod
		
	return prod

count = 1
counts = []
cnt_current = 0
zero_count = 0
for num in nums[1:]:
	if num > count:
		counts.append(cnt_current)
		if num - count > 1:
			print(0)
			exit()
		cnt_current = 1
		count = num
	else:
		cnt_current += 1
		
if count > 1:
	counts.append(cnt_current)
		
#print(counts)
		
if count == 1:
	print(1)
	exit()
	
out = 1
for i in range(len(counts) - 1):
	out *= pow_mod(counts[i],counts[i+1]) % mod
	
print(out)

Submission status: Wrong Answer

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

INF = 998244353

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

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


def pos(x, n, m):
    if n == 0:
        return 1
    res = pos(x*x%m, n//2, m)
    if n%2 == 1:
        res = res*x%m
    return res


res = 1
pre = 1

for i in range(1,N):
    now = D.count(i)
    if now == 0:
        break
    res = res * pos(pre,now,INF)
    pre = now

print(res)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)#{0:1,1:3,2:4}
keys = sorted(c.keys())#[0,1,2,4]
max = keys[len(keys)-1]#2
ok = True#check
if c[0] != 1:#1
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:#数字が並んでるか
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = False
            break
        count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*(pow(c[i],c[i+1])%998244353)
        ans = ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
ans = 1
x = 1
y = 1

d.sort()
for i in range(n - 2):
    if d[1] == 0 or d[0] != 0:
        ans *= 0
        break
    if d[i + 1] == d[i + 2]:
        x += 1
    elif d[i + 1] == d[i + 2] - 1:
        if d[i + 1] > 1:
            for j in range(x):
                ans *= y
            y = x
            x = 1
        else:
            y = x
            x = 1

for j in range(x):
    ans *= y
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import time

n = int(input())
L = [int(i) for i in input().split()]
LL = np.zeros(pow(10,5)+1, dtype="object")
LLL = np.array([1 for i in range(pow(10,5)+1)], dtype="object")
T = np.array([int(i) for i in range(pow(10,5)+1)], dtype="object")

for i in range(n):
  LL[L[i]] += 1

LLL = (T**LL)%998244353
LLL[0] = 1
out = 1  

for i in range(len(LLL)):
  out *= LLL[i]
  out = out % 998244353

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


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


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

Sum = 1

for i in range(len(x)):

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

print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
import numpy as np
from itertools import accumulate

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

if not D[0] == 0:
    print("0")
elif D.count(0) >= 2:
    print("0")
else:
    for i in range(max(D)):
        if not i in D:
            print("0")
            exit()        
    D.sort()
    ans = [D.index(i) for i in range(1,max(D)+1)]
    sabun = [ans[i] - ans[i-1] for i in range(1,len(ans))]
    sabun.append(N-ans[-1])
    ans = [(i+1)**sabun[i] for i in range(len(sabun))]
    ans = np.prod(ans, axis = 0)
    print(ans%998244353)

Submission status: Wrong Answer

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

div_num = 998244353
result = 1
ct_l = []

for i in range(max(l)+1):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1

#print(ct_l)
prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    #print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v
    result %= div_num
    prev_v = curr_v
    #print(prev_v, curr_v, result)

if e < 0 or l[0] > 0:
    print(0)
elif n == l[1]:
    print(1)
else:
    print(result)

Submission status: Wrong Answer

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


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

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

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])
    if count == 1:
        print(0)
        exit()
    print(count % MOD)




    

if __name__ == '__main__':
    main()

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

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

Submission status: Wrong Answer

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

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)

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()
if d[0][1] != 1:
    print(0)
    sys.exit()
ans = 1   
float(ans)
for i in range(1,len(d)):
    for _ in range(d[i][1]):
        ans = ((ans * i) % mod)
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    #if d[0] != 0:
    #    print(0) 
    

    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:
                tmp = j
                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
c=[0 for i in range(max(d)+1)]
for x in d:
  c[x]+=1
if d[0]!=0 :
  print(0)
  exit()
p=1
for x in c:
  ans*=p**x%998244353
  p=x
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

M = 998244353
n = int(input())
d = sorted(map(int, input().split()))
counter = Counter(d)

ans = 1
for i in range(d[-1] + 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 sys
input = sys.stdin.readline

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1

if l[0] != (0, 1):
    answer = 0
else:
    for i in range(M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    ans = 1
    for i in range(len(C) -1):
        if C[i] == 0:
            ans = 0
            break
        ans *= C[i] ** C[i+1]
    
    print(ans % 998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

if len(m) < n:
    print(0)
    sys.exit()

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

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

print(ans % 998244353)

Submission status: Wrong Answer

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

c = Counter(d)

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

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        if tmp == cnt[i]:
            continue
        else:
            c = (tmp**cnt[i]) % mod
            ans *= c % mod
            tmp = cnt[i]
            ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

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

res = 1
if D_list.count(0) == 1:
    for i in range(0, max(D_list)):
        if D_list.count(i)!=0:
            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())
D = list(map(int, input().split()))


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


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

Sum = 1

for i in range(len(x)):

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

print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import numpy as np

def main():
    N = int(input())
    Ds = np.array([int(d) for d in input().split()])

    Ds.sort()
    if Ds[Ds==0].size != 1:
        print(0)
        return
    Ds = Ds[1:]

    l = 0
    r = 1
    c = []
    while Ds.size > 0:
        l = l + 1
        cnt = Ds[Ds==l].size
        if cnt == 0:
            print(0)
            return
        c.append((r, cnt))
        r = cnt
        Ds = Ds[cnt:]
        
    ans = 1
    divider = 998244353
    for i, j in c:
        if j > 10:
            j1 = j//2
            j2 = j - j//2
            r1 = (i**j1)%divider
            r2 = (i**j2)%divider
            r = (r1*r2)%divider
        else:
            r = (i**j)%divider
        ans = (ans*r)%divider
    
    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",main)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
E = str(input())
l = E.split()
li = [int(s) for s in l]
li.sort()
for i in range(N):
  co = 0
  if li[i] == 0:
    co += 1
    if co > 2 or (li[i]>1 and co == 0):
      print(0)
      break
else:
#  print(li)
  cp = []
  for j in range(N):
    cp.append(0)
    for i in li:
        if i == j:
            cp[i] += 1
 # print(cp)
  ans = 1
  for i in range(2,len(cp)):
    if cp[i] != 0 :
      ans*=cp[i-1]**cp[i]
  print(ans%998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
elif d[-1] > n-1:
  print("0")
else:
  for i in range(1,max(d)+1):
    li.append(d.count(i))
  for i in range(len(li)-1):
    li[i] = li[i]%998244353
    ans = (ans*((li[i]**li[i+1])%998244353)%998244353)
  print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = list(map(int, input().split()))
    ans = 1
    tmp = -1
    if d[0] != 0:
        print(0)
    else:
        c = collections.Counter(d)
        if 0 in c.keys() and c[0] > 1:
            print(0)
            exit()
        for i in range(1, n):
            if i in c.keys():
                if i == 1:
                    ans *= c[1]
                else:
                    ans = (ans ** c[i]) * c[i]
            else:
                tmp = i
                break
        for i in range(tmp + 1, n):
            if i in c.keys():
                print(0)
                exit()
        print(ans % 998244353)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
  
N = int(input())
D = list(map(int, input().split()))
D.sort()
ans = 1
e = 0
  
l = collections.Counter(D)  
 
for i in range(N-1):
  if l[i] != 0:
      ans *= l[i] ** l[i+1]
 
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1
     

if D.count(0) != 1 or e == 1:
  print(0)
elif N == 1:
  print(1)
else:
  print(ans%998244353)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1
if M > 1:
    for i in range(1, l[1][1]):
        answer *= i
else:
    answer = 1

if l[0] != (0, 1):
    answer = 0
else:
    for i in range(1, M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
l=[]
ans=1
for i in range(max(d)):
  if not i in d:
    ans=0
    break
for i in range(1,n):
  l.append(d.count(i))
if l.index(0)+1:
  del l[l.index(0):]
for j in range(len(l)-1):
  ans *= l[j]**l[j+1]
print(ans%998244353)

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 *= countl[i] ** countl[i + 1]
print(ans % 998244353)

Submission status: Wrong Answer

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

ans = 1
for i in d:
    if i != 0:
        ans *= cnt[i-1]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import tee

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


def pairwise(iterable):
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


def is_leap(distance):
    cc = Counter(distance)
    for x, y in pairwise(sorted(cc.keys())):
        print(x, y, y - x)
        if y - x > 1:
            return True
    else:
        return False


if D[0] > 0:
    """頂点1が根ではない"""
    print(0)
elif not all(D[1:]):
    """連結グラフではない"""
    print(0)
elif is_leap(D):
    print(0)
else:
    ans = 1
    c = Counter(D[1:])
    edges = [t[1] for t in sorted(c.items())]
    for d, e in pairwise(edges):
        ans *= pow(d, e)
    print(ans % R)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
x=1
for i in range(listx[-1]):
  print(i+1)
  x*=listx.count(int(i+1))+1
if listx[0]!=0:
  x=0
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
D = list(map(int, input().split()))
D.sort()
a=0
c=0
f=1
e=1
end=0
for i in range(n):
  if(D[i]==a):
    c+=1
    if(c>2**a):
      print(0)
      end=1
      break
  else:
    e*=f**c
    f=c
    c=1
    a+=1
e*=f**c
if(end==0):
  print(int(e))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0]*N
for D in Ds:
    counter[D] += 1
total = 0
cnt = 0
prenumi = 0
for i in range(N):
    if i == 0:
        if counter[i] == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = counter[i]
        if numi != 0:
            case = 1
            for j in range(numi):
                case = (case * prenumi) % CONST_DIVSOR
            total = (total * case) % CONST_DIVSOR
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break
 
print(total % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    from collections import defaultdict
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d[0] != 0 or d.count(0) != 1:
        print(0)
    else:
        count = 1
        dc = defaultdict(int)
        for i in d[1:]:
            dc[i] += 1
        for i in range(1, d[-1]):
            count = ((count % mod) * ((dc[i]**dc[i+1]) % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    from collections import defaultdict
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d[0] != 0 and d.count(0) != 1:
        print(0)
    else:
        count = 1
        dc = defaultdict(int)
        for i in d[1:]:
            dc[i] += 1
        for i in range(1, d[-1]):
            count = ((count % mod) * ((dc[i]**dc[i+1]) % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)#{0:1,1:3,2:4}
keys = sorted(c.keys())#[0,1,2,4]
max = keys[len(keys)-1]#2
ok = True#check
if c[0] != 1:#1
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:#数字が並んでるか
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = False
            break
        count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*pow(c[i],c[i+1])
        ans =  ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353

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


# import sys
# sys.setrecursionlimit(10000000)
# def input():
#     return sys.stdin.readline()[:-1]
# from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
# INF = float('inf')
# # MOD = 10**9+7
# MOD = 998244353
#
# N = int(input())
# D = list(map(int, input().split()))
# if D[0] != 0:
#     print(0)
# C = Counter(D)
# ans = 1
# for i in range(1, max(D)+1):
#     if C[i] == 0:
#         ans = 0
#         break
#     else:
#         ans *= pow(C[i-1], C[i], MOD)
#         ans %= MOD
# print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
mx = 0
ans = 1
lv = [0 for x in range(n+1)]
for i in input().split():
	i = int(i)
	lv[i] += 1
	mx = max(mx, i)
for i in range(mx):
	ans = ans * lv[i]**lv[i+1]
print(ans % 998244353)

Submission status: Wrong Answer

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


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


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

Sum = 1

for i in range(len(x)):

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

print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
elif d[-1] > n-1:
  print("0")
else:
  for i in range(1,max(d)+1):
    li.append(d.count(i))
  for i in range(len(li)-1):
    k=1
    for l in range(li[i+1]):
      k = k*li[i]
      if k > 998244353:
        k = k%998244353
    ans = (ans*(k%998244353)%998244353)
  print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
l=[]
ans=1
for i in range(max(d)):
  if not i in d:
    ans=0
    print(i)
    break
for i in range(1,n):
  l.append(d.count(i))
if l.index(0)+1:
  del l[l.index(0):]
for j in range(len(l)-1):
  ans *= l[j]**l[j+1]
print(ans)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    from collections import defaultdict
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d[0] != 0:
        print(0)
    else:
        count = 1
        dc = defaultdict(int)
        for i in d[1:]:
            dc[i] += 1
        for i in range(1, d[-1]):
            count = ((count % mod) * ((dc[i]**dc[i+1]) % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

div_num = 998244353
result = 1
ct_l = []

for i in range(max(l)+1):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1

#print(ct_l)
prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    #print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v
    result %= div_num
    prev_v = curr_v
    #print(prev_v, curr_v, result)


if e < 0 or l[0] > 0:
    print(0)
else:
    print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

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

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

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