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

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

else:
    cnt = Counter(d)
max_c = max(cnt)
ans = 1
for i in range(1, max_c+1):
    ans *= pow(cnt[i-1], cnt[i], MOD) % MOD

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

for i in range(max_c + 1):
    if i not in cnt:
        ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

else:
    cnt = Counter(d)

ans = 1
for i in range(1, n):
    ans *= pow(cnt[i-1], cnt[i], MOD) % MOD

if cnt[0] != 1:
    ans = 0
max_c = max(cnt)
for i in range(max_c + 1):
    if i not in cnt:
        ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

else:
    cnt = Counter(d)

ans = 1
for i in range(2, n):
    ans *= pow(cnt[i-1], cnt[i], MOD) % MOD

if cnt[0] != 1:
    ans = 0
max_c = max(cnt)
for i in range(max_c + 1):
    if i not in cnt:
        ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

else:
    cnt = Counter(d)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
if d[0] != 0:
    print(0)
    exit()

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

ans = 1
for i in range(2, n):
    ans *= pow(cnt[i-1], cnt[i], MOD) % MOD
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] == 0:
    print(0)
    exit()
else:
    cnt = [0]*n
    for i in range(1, n):
        cnt[d[i]] += 1

ans = 1
for i in range(2, n):
    ans *= cnt[i-1]**cnt[i] % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
cnt = [0]*n
for i in range(n):
    cnt[d[i]] += 1
        
if d[0] != 0 or cnt[0] > 1:
    print(0)
    exit()
        
ans = 1
for i in range(1, n):
    if cnt[i] == 0:
        break
    ans *= cnt[i-1]**cnt[i] % MOD
print(ans)

Submission status: Wrong Answer

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

cnt = [0]*n
for i in range(n):
    cnt[d[i]] += 1
        
if d[0] != 0 or cnt[0] > 1:
    print(0)
    exit()
        
ans = 1
for i in range(1, n):
    x = d[i]
    y = cnt[x-1]
    ans *= y
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] == 0:
    print(0)
    exit()
else:
    cnt = [0]*n
    for i in range(n):
        cnt[d[i]] += 1

ans = 1
for i in range(1, n):
    x = d[i]
    y = cnt[x-1]
    ans *= y
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] == 0:
    print(0)
    exit()
else:
    cnt = [0]*n
    for i in range(1, n):
        cnt[d[i]] += 1

ans = 1
for i in range(2, n):
    ans *= cnt[i-1]**cnt[i]
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] == 0 or d[n-1] >= n:
    print(0)
    exit()
else:
    cnt = [0]*n
    for i in range(1, n):
        cnt[d[i]] += 1

ans = 1
for i in range(2, n):
    if cnt[i] == 0:
        break
    ans *= cnt[i-1]**cnt[i]
print(ans)

Submission status: Wrong Answer

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

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

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

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(1, max(D)+1):
# print(tmp)
for kx in range(2, len(tmp)):
    # print(kx)
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    # p = cd[kx-1]
    # v = cd[kx]
    # print("{}^{}".format(p, v))
    while v > 0:
        ans *= p
        ans %= M
        v -= 1
# print(cd)

# for kx in range(1, max(D)+1):
#     ans *= pow(cd[kx-1], cd[kx],M)
#     ans %= M

print(ans)

Submission status: Wrong Answer

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

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

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

tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(2, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    while v > 0:
        ans *= p
        ans %= M
        v -= 1


print(ans)

Submission status: Wrong Answer

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

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

cd = Counter(D)
if cd[0] != 1:
    print(0)
    exit(0)
    
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
# print(cd)
for kx in range(1, len(tmp)-1):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    # ans *= p**v%M
    while v > 0:
        ans = ans*p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

try:
    if D[1:].index(0):
        print(0)
        exit(0)
except ValueError as e:
    pass

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
# print(cd)
for kx in range(1, len(tmp)-1):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    # ans *= p**v%M
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
# print(cd)
for kx in range(1, len(tmp)-1):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    # ans *= p**v%M
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
# for kx in range(2, len(tmp)):
#     __, p = tmp[kx-1]
#     _, v = tmp[kx]
#     while v > 0:
#         ans *= p%M
#         v -= 1
for kx in range(1, len(tmp)-2):
    _, p = tmp[kx]
    __, v = tmp[kx+1]
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(2, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(1, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    while v > 0:
        ans *= p%M
        v -= 1

print(ans%M)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(1, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    while v > 0:
        ans *= p %M
        v -= 1

print(ans)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(1, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    ans *= p**v %M

print(ans)

Submission status: Wrong Answer

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

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

cd = Counter(D)
tmp = sorted(cd.items(), key=lambda x: x[0])

ans = 1
for kx in range(2, len(tmp)):
    __, p = tmp[kx-1]
    _, v = tmp[kx]
    ans *= p**v %M

print(ans)

Submission status: Wrong Answer

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

e=max(d)
sm=1
for i in range(1,e+1):
  if i==0:
    print(0)
    break
  sm=(sm*d.count(i-1)**d.count(i))%998244353
print(sm)

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

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
D=list(map(int,input().split()))
mod=998244353
D=collections.Counter(D)
if D[0]!=1 or D[0]!=0:
  print(0);exit()
ans=1
l=1
for i in range(len(D)):
  if i==0:
    continue
  
  ans*=pow(l,D[i],mod)
  ans%=mod
  l=D[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
D=list(map(int,input().split()))
mod=998244353
D=collections.Counter(D)
if D[0]!=1:
  print(0);exit()
ans=1
l=1
for i in range(len(D)):
  if i==0:
    continue
  
  ans*=pow(l,D[i],mod)
  ans%=mod
  l=D[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
  ans = 1
  for i in range(1, m+1):
    ans *= c[i-1]**c[i]
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
Dc = Counter(D)
mod = 998244353
ans = 1

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
Dc = Counter(D)
mod = 998244353
ans = 1

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

Submission status: Wrong Answer

Solution code:
from math import factorial as fac
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
Dc = Counter(D)
mod = 998244353
ans = 1

if Dc[0]!=1:
    print(0)
else:
    for i in range(max(D)):
        ans *= fac(Dc[i])%mod
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
from math import factorial as fac
n = int(input())
D = list(map(int,input().split()))
mod = 998244353
ans = 1

if D.count(0)!=1:
    print(0)
else:
    for i in range(max(D)):
        ans *= fac(D.count(i))%mod
    print(ans)

Submission status: Wrong Answer

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

c = Counter(D)
mod = 998244353
L = list(set(D[:]))
L.sort(reverse=True)
if (D[0] != 0):
    print(0)
    exit()
elif (c[0] > 1):
    print(0)
    exit()

if (N == 1):
    print(1)
    exit()


ans = 1
for i in L:
    if (i == 1):
        ans *= 1
        break
    if (c[i - 1] == 0 and i != 1):
        print(0)
        exit()
    else:
        ans *= c[i - 1] ** c[i]

print(ans)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

if 0 not in D:
    print(0)
    exit()


ans = []
for i in L:
    if (c[i - 1] == 0):
        ans.append(c[i])
        continue
    ans.append(c[i - 1] ** c[i])

if (len(ans) == 0):
    print(0)
    exit()
# print(ans)
multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

if 0 not in D:
    print(0)
    exit()


ans = []
for i in L:
    if (c[i - 1] == 0):
        ans.append(c[i])
        continue
    ans.append(c[i - 1] ** c[i])

if (len(ans) == 0):
    print(0)
    exit()
print(ans)
multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

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


ans = []
for i in L:
    if (i == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])

# print(ans)
if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

ans = []
for i in L:
    if (i == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])

# print(ans)
if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)
if (c[0] > 1):
    print(0)
    exit()

ans = []
for i in L:
    if (i - 1 == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])

if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

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

c = Counter(D)

mod = 998244353

L = list(set(D[:]))

L.sort(reverse=True)

ans = []
for i in L:
    if (i - 1 == 0):
        break
    else:
        ans.append(c[i - 1] ** c[i])

if (len(ans) == 0):
    print(0)
    exit()

multi_ans = 1
for i in ans:
    multi_ans *= i

print(multi_ans % mod)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    D = in_nl()
    mod = 998244353

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

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

    zero = N + 1
    non_zero = -1
    for i in range(N):
        if count[i] == 0:
            zero = min(zero, i)
        else:
            non_zero = max(non_zero, i)

    if zero < non_zero:
        print(0)
        exit()

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    nums = [0]*n
    for d in D:
        nums[d] += 1
    
    imp = False
    end = False
    
    if nums[0] > 1:
        imp = True
        
    for i in range(1,n):
        if nums[i] == 0:
            end = True
        else:
            if end:
                imp = True
                break
            
    if imp:
        print(0)
    else:
        ans = 1
        for i in range(1,n):
            if nums[i] == 0:
                break
            ans *= pow(nums[i-1], nums[i], mod)%mod
        print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
#mod = 10 ** 9 + 7 
mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = LIST()

d = Counter(D)

if d[0] == 1 and D[0] == 0:
	pass
else:
	print(0)
	exit()

ans = 1
tmp = 1
for i in range(max(d.values())+1):
	ans = ans * pow(tmp, d[i], mod) % mod
	tmp = d[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = LIST()

d = Counter(D)

if d[0] == 1 and D[0] == 0:
	pass
else:
	print(0)
	exit()

ans = 1
tmp = 1
for i in range(max(d.values())+1):
	if d[i] == 0:
		print(0)
		exit()
		
	ans = ans * pow(tmp, d[i], mod) % mod
	tmp = d[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
D = LIST()

d = Counter(D)

if d[0] == 1 and D[0] == 0:
	pass
else:
	print(0)
	exit()

ans = 1
tmp = 1
for i in range(max(d.values())+1):
	ans = ans * pow(tmp, d[i], mod) % mod
	tmp = d[i]

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
lis = [0] * (max(D)+1)
for i in D:
    lis[i] += 1
if lis[0] == 0 or lis[0] > 1:
    print(0)
    exit()


ans = 1
for i in range(1,len(lis)):
    ans *= pow(lis[i-1],lis[i], MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
lis = [0] * (max(D)+1)
for i in D:
    lis[i] += 1
if lis[0] > 1:
    print(0)
    exit()
if 0 in lis:
    print(0)
    exit()

ans = 1
for i in range(1,len(lis)):
    ans *= pow(lis[i-1],lis[i], MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
lis = [0] * (max(D)+1)
for i in D:
    lis[i] += 1
if lis[0] > 1:
    print(0)
    exit()
for i in lis:
    if i == 0:
        print(0)
        exit()

ans = 1
for i in range(1,len(lis)):
    ans *= pow(lis[i-1],lis[i], MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

def power(x,n,MOD):
    res=1
    if n>0:
        res=power(x,n//2,MOD)
        if (n%2==0):
            res=(res*res)%MOD
        else:
            res=(((res*res)%MOD)*x)%MOD
    #print(x,n,MOD,res)
    return res

def main(n,d):
    MOD=998244353
    hist=[0]*(n+1)
    maxd=0
    for i in range(n):
        hist[d[i]]+=1
        maxd=max(maxd,d[i])
    #print(hist,maxd)

    ans=1
    if hist[0]>1:
        return 0
    for i in range(1,maxd+1):
        #print(i, hist[i-1], hist[i])
        ans=(ans*power(hist[i-1], hist[i], MOD))%MOD
        #print(ans)

    return ans

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)

Submission status: Wrong Answer

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

def power(x,n,MOD):
    res=1
    if n>0:
        res=power(x,n//2,MOD)
        if (n%2==0):
            res=(res*res)%MOD
        else:
            res=(((res*res)%MOD)*x)%MOD
    #print(x,n,MOD,res)
    return res

def main(n,d):
    MOD=998244353
    hist=[0]*(n+1)
    maxd=0
    for i in range(n):
        hist[d[i]]+=1
        maxd=max(maxd,d[i])
    #print(hist,maxd)

    ans=1
    if hist[0]>1:
        hist[0]=1
    for i in range(1,maxd+1):
        #print(i, hist[i-1], hist[i])
        ans=(ans*power(hist[i-1], hist[i], MOD))%MOD
        #print(ans)

    return ans

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)

Submission status: Wrong Answer

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

def power(x,n,MOD):
    res=1
    if n>0:
        res=power(x,n//2,MOD)
        if (n%2==0):
            res=(res*res)%MOD
        else:
            res=(((res*res)%MOD)*x)%MOD
    #print(x,n,MOD,res)
    return res

def main(n,d):
    MOD=998244353
    hist=[0]*(n+1)
    maxd=0
    for i in range(n):
        hist[d[i]]+=1
        maxd=max(maxd,d[i])
    #print(hist,maxd)

    ans=1
    hist[0]=1
    for i in range(1,maxd+1):
        #print(i, hist[i-1], hist[i])
        ans=(ans*power(hist[i-1], hist[i], MOD))%MOD
        #print(ans)

    return ans

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)

Submission status: Wrong Answer

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

def power(x,n,MOD):
    res=1
    if n>0:
        res=power(x,n//2,MOD)
        if (n%2==0):
            res=(res*res)%MOD
        else:
            res=(((res*res)%MOD)*x)%MOD
    #print(x,n,MOD,res)
    return res

def main(n,d):
    MOD=998244353
    hist=[0]*(n+1)
    maxd=0
    for i in range(n):
        hist[d[i]]+=1
        maxd=max(maxd,d[i])
    #print(hist,maxd)

    ans=1
    for i in range(1,maxd+1):
        #print(i, hist[i-1], hist[i])
        ans=(ans*power(hist[i-1], hist[i], MOD))%MOD
        #print(ans)

    return ans

if __name__=='__main__':
    n,d=readinput()
    ans=main(n,d)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
"""
def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)
"""

for i in D[1:]:
    ans *= i
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
"""
def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)
"""

for i in D[1:]:
    ans *= C[i-1] % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
"""
def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)
"""

for i in D[1:]:
    ans *= i % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

if D[0] != 0:
    ans = 0
else:
    count = sorted(Counter(D).items(), key=lambda x: x[0])
    ans = 1
    for i in range(len(count) - 1):
        x = count[i][1]
        y = count[i + 1][1]
        ans *= x ** y
        ans %= p

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

if D[0] != 0 or len(set(D)) != max(D) + 1:
    ans = 0
else:
    count = sorted(Counter(D).items(), key=lambda x: x[0])
    ans = 1
    for i in range(len(count) - 1):
        x = count[i][1]
        y = count[i + 1][1]
        ans *= x ** y
        ans %= p

print(ans % p)

Submission status: Wrong Answer

Solution code:
from collections import Counter


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

if D[0] != 0 or len(set(D)) != max(D) + 1:
    ans = 0
else:
    count = sorted(Counter(D).items(), key=lambda x: x[0])
    ans = 1
    for i in range(len(count) - 1):
        x = count[i][1]
        y = count[i + 1][1]
        ans *= x ** y
        ans %= p

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

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

def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)


for i in range(1,D_max+1):
    if C[i-1] == 1:
        ans *= C[i]
    else:
        ans *= nCr(C[i-1]-1+C[i],C[i-1]-1) % mod
    if ans == 0:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    D = [int(item) for item in input().split()]
    d_dict = collections.Counter(D)
    print(D)
    print(d_dict)

    cnt = 0
    if D[0] != 0:
        pass
    else:
        cnt = 1
        for i in D[1:]:
            cnt *= d_dict[i-1]
            cnt %= 998244353


    print(cnt % 998244353)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    D = [int(item) for item in input().split()]
    d_dict = collections.Counter(D)

    cnt = 0
    if D[0] != 0 and D.count(0) > 1:
        pass
    else:
        cnt = 1
        for i in D[1:]:
            if i >0 :
                cnt *= d_dict[i-1]

            cnt %= 998244353


    print(cnt % 998244353)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    D = [int(item) for item in input().split()]
    d_dict = collections.Counter(D)

    cnt = 0
    if D[0] != 0 and D.count(0) != 1:
        pass
    else:
        cnt = 1
        for i in D[1:]:
            if i >0 :
                cnt *= d_dict[i-1]

            cnt %= 998244353


    print(cnt)

if __name__ == "__main__":
    resolve()