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


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

maxd = max(d)
mem = [1 for i in range(n+1)]
for y in range(maxd):
  mem[y] = d.count(y)

count = 1
for i in range(maxd):
  count = count * mem[i] ** mem[i+1]
  
print(count % 998244353)

Submission status: Wrong Answer

Solution code:
# B - Counting of Trees
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

# c = Counter(D)
# c.most_common()
ans = 1
if D[0] == 1:
    print(0)
    exit()
else:
    for i in range(len(D)):
        if D[i] == 0:
            pass
        else:
            ans *= D[i]
            ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
for i in range(1,N):
    ans = ans * D[i]
if D[0] != 0:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


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

a = collections.Counter(num_list)
maxim = sorted(num_list)[-1]

flag = 0
ans = 1
for i in range(1,maxim+1):
    if a[i-1] == 0:
        flag = 1
        break
    if a[i-1] != 1 and a[i] == 1:
        ans = ans * (a[i-1])
    
    elif a[i-1] != 1 and a[i] > a[i-1]:
        ans = ans * a[i-1] * (a[i-1] + (a[i]-1))
    elif a[i-1] != 1 and a[i] <= a[i-1]:
        ans = ans * a[i-1] * (a[i-1] + cmb(a[i-1], a[i]))
    
    elif a[i-1] == 1:
        ans = ans
    else:
        ans = ans * (a[i])
if flag == 1:
    print(0)
else:
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import collections


def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    if counter[0] != 1:
        return 0
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

Submission status: Wrong Answer

Solution code:
import collections
import operator

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

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

# l = []
# for i in range(int(max(D))):
#     if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]
#     l.append()

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

print(ans)

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 D[0] != 0:
    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()))

r = [None] * N
m = 0

for i, j in enumerate(D):
    if i == 0 and j != 0:
        print("0")
        exit()
    r[j] = 1 if r[j] is None else r[j] + 1
    if j > m:
        m = j

result = 1
pre = None

for i, x in enumerate(r):
    if x is None:
        if i <= m:
            print("0")
            exit()
        else:
            break
    if i < 2:
        pre = x
        continue
    result *= pre**x
    pre = x

print(result)

Submission status: Wrong Answer

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
import math

n = int(input())
d = list(map(int, input().split()))
num = 998244353
flag = True

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

x.pop(0)


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(len(x)-1):
    pre_num = x[i][1]
    forward_num = x[i+1][1]
    if flag is True:
        if pre_num == 1:
            ans *= forward_num
        elif forward_num == 1:
            ans *= pre_num
            flag = False
        elif pre_num < forward_num:
            ans *= math.factorial(pre_num) * cmb(forward_num+1, pre_num-1)
        else:
            ans *= (pre_num + cmb(pre_num, forward_num) * math.factorial(forward_num))
        ans = ans % num
    else:
        if pre_num >= 1:
            print(0)
            exit()

print(ans)

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):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


if D[0] > 0:
    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 = int(input())
d = list(map(int,input().split()))
 
ans = 1
if min(d) != 0:
  ans = 0
d.sort()
for i in range(1,max(d)+1):
  ans *= d.count(i-1)**d.count(i)
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
for i in range(1,maxkey): 
    ans=ans*(dic[i]**dic[i+1])%MOD
print(ans)

Submission status: Wrong Answer

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

d.sort()
dd=[0]*10**5
max=0
for i in d:
    dd[i]+=1
    if(max<i):
        max=i

ans=True
now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in dd[1:max+1]:
    if(i==0):
        ans=False
    now=now*(before**i) % 998244353
    before=i
    #print(i)

if(ans):
    print(now)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = [int(i) for i in input().split()]
ans = 0
if d[0] == 0:
    s = collections.Counter(d)
    ss = sorted(s.items())
    if ss[0][1] == 1:
        ans = 1
        for i in range(1,len(ss)):
            if ss[i][0] != ss[i-1][0] + 1:
                ans = 0
                break
            ans *= ss[i-1][1]**ss[i][1]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

const = 998244353

c = collections.Counter(d)

m = max(d)

if c[0] != 1:
    print(0)
else:
    ans = c[0]
    for i in range(m):
        j = i + 1
        old = c[j - 1]
        new = c[j]
        if new == 0:
            ans = 0
            break
        else:
            ans = ans * (pow(old, new) % const) % const

    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
d = [int(i) for i in input().split()]

initial = d[0]
maximum = max(d)
d = collections.Counter(d)

ans=1
for n in range(initial, maximum):
    if d[n] == 0:
        print(0)
        exit()
    else:
        ans *= d[n] ** d[n+1]
print(ans)

Submission status: Wrong Answer

Solution code:
i = int(input()) 
list = [int(i) for i in input().split()]

def unique(list1): 
    unique_list = [] 
      
    for x in list1: 
        if x != 0 and x != 1:
            unique_list.append(x) 
    return unique_list

  
def multiplyList(myList) : 
      
    # Multiply elements one by one 
    result = 1
    for x in myList: 
         result = result * x  
    return result 

print(multiplyList(unique(list)))

Submission status: Wrong Answer

Solution code:
import collections


def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
#入力
n = int(input())
d = list(map(int,input().split()))

a = []

for i in range(n-1):
	a.append(d.count(i))
	#print(i,a)

ans = 1
for i in range(n-2):
	ans = ans * pow(a[i],a[i+1])

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    D = list(map(int, input().split()))
    count = Counter(D[1:])
    if D[0] != 0:
        # 頂点1に対しては、0以外有り得ない
        print(0)
        return
    results = [0, 1]
    for d in sorted(count.keys())[1:]:
        results.append(results[-1] * count[d - 1] ** count[d])
    print(results[-1] % 998244353)


if __name__ == "__main__":
    main()

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) 
    
    else:
        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        ans = 1
        tmp = 1
        for i,j in items:
            if i == 0:
                tmp = j
                continue

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

        print(ans)


if __name__ == '__main__':
    main()

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):
    "s -> (s0,s1), (s1,s2), (s2, s3), ..."
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)


if D[0] > 0:
    print(0)
else:
    ans = 1
    c = Counter(D[1:])
    print(c)
    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:
import numpy as np
import collections

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

D_seq_max = max(D_seq)

judge_list = np.arange(D_seq_max+1)
judge_set = set(judge_list)
D_seq_set = set(D_seq)

c = collections.Counter(D_seq)

N_list = []
if((judge_set == D_seq_set)or(D_seq[0]==0)):
    counts = 1
    for i in range(D_seq_max):
        counts *= pow(c[i], c[i+1])
    if(counts < 998244353):    
        print(counts)
    else:
        print(int(counts%998244353))
        
else:
    print(0)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx < 2:
        if tree == 0:
            count = 0
    if tree == 0:
        count *= 0
    else:
        count *= tree_list[idx - 1]**tree
print(count%998244353)

Submission status: Wrong Answer

Solution code:

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

if not D[0] == 0:
    print(0)
else:
    ans = 1
    s = set()
    for i in range(1,len(D)):
        ans *= D[i]
        s.add(D[i])

    #print(s)
    s_l = list(s)
    #print(s_l)
    #print(ans)
    if s_l[len(s_l)-1] == len(s_l):
        print(ans)
    else:
        print(0)

Submission status: Wrong Answer

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

n = int(input())
dd = list(map(int, input().split()))
dd.sort()
ls = []
ans = 1

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

for i in range(n):
    cnt = dd[:i].count(max(dd[:i+1])-1)
    ls.append(cnt)
    if max(ls)+1 >= dd[i]:
        ans *= max(cnt, 1)
    else:
        print(0)
        exit()

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 1
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    d_max = max(d_l)
    count_dic = collections.Counter(d_l)
    for i in range(2, d_max+1):
        ans *= count_dic[i-1] ** count_dic[i]
    
    print(ans%MOD)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or len(set(d))!=max(d)+1 or 0 in d[1:]:
    print(0)
else:
    for i in range(1,len(c)):
        ans *= c[i-1]**c[i] %m
    print(ans)

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(n):
    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):
    #print(i, item, e, result)
    if i < 2:
        if i == 0 and item == 1:
            pass
        else:
            e -= item
        if i == 1:
            prev_v = item

        continue
    e -= item
    if e < 0:
        print(0)
        exit()
    if item == 0:
        break

    curr_v = item
    result *= prev_v**curr_v
    prev_v = curr_v
    #print(prev_v, curr_v, result)

print(result)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def count_tree(d):
    n = max(int(i) for i in d.keys())
    cnt = 1
    if d["0"] != 1:
        return 0
    for i in range(1, n):
        if d[str(i + 1)] > 0 and d[str(i)] < 1:
            return 0
        else:
            cnt *= d[str(i)] ** d[str(i + 1)] % 998244353
    return cnt

input()
print(count_tree(Counter(input().split())))

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
s = list(map(int, input().split()))
item = 0
sum = 0
node = 0
count = 0
before = 0

c = collections.Counter(s)

for i in range(N):
    count = c[i]
    node += count

    if i == 0:
        if count != 1:
            break
        else:
            before = 1
            sum = 1
    else:
        if count == 0:
            break
        else:
            sum = sum * (c[i-1] ** count)
            before = count

if node != len(s):
    print("0")
else:
    print(sum%998244353)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
M = 998244353
N = int(input())
# D = list(map(int, input().split()))
counter = Counter(input().split())
ans = 1
for i, (n, c) in enumerate(sorted(counter.items())):
    n = int(n)
    if i != n:
        ans = 0
        break
    elif n == 0:
        continue
    ans *= n ** c
print(ans % M)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
 
import numpy as np
if D[0]!=0:
  print(0)
elif len(set(D))!=(max(D)+1):
  print(0)
else:
  for i in range(D.count(0)):
    D.remove(0)
  print(int(np.prod(D)))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar)
    check_ar = list(set(ar))
    # for i in range(len(check_ar) - 1):
    #     if check_ar[i] + 1 != check_ar[i + 1]:
    #         ngflg = True
    if ngflg:
        print("0")
    else:
        ans_ar= []
        ans = 1
        for k, g in groupby(ar):
            if int(k) != 0:
                ans *= int(k) ** len(list(g))
        print(ans % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Wrong Answer

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

max_vertex = max(l)
ll = []
l=sorted(l)
l.append(-4)
c=1
for i in range(1, n):
    if l[i] != l[i+1]:
        if l[i] != l[i+1]-1 and l[i+1] > 0:
            print(0)
            exit()
        ll.append(c)
        c = 0
    c+=1
   
count = 1
for i in range(1, max_vertex):
    tmp = ll[i-1]
    count *= pow(tmp, ll[i])
print(count%998244353)

Submission status: Wrong Answer

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

    if d[0] != 0:
        print(0)
    else:
        k = max(d)
        a = [0] * (k+1)
        for i in range(1,n):
            a[d[i]] += 1
        if a[0] > 0:
            print(0)
        else:
            r = 1
            for i in range(2, k+1):
                r *= a[i-1] ** a[i]
            print(r)




if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, max(a)+1):
        if a.count(i) != 0:
            output *= pow(a.count(i-1),a.count(i),998244353)
    print(output)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
d_list = [num for num in map(int, input().split(' '))]

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

# print(n)
# print(d_list)

ans = 0

d_max = max(d_list)
layer = [0] * (d_max+1)
touri = [0] * (d_max+1)

if d_list[0] != 0:
  print(0)
  sys.exit()
else:
  layer[0] = 1

for i in range(1, n):
  d = d_list[i]
  if d == 0:
    print(0)
    sys.exit()
  layer[d] += 1

touri[0] = 1
for i in range(1, len(layer)):
  count = layer[i]
  prev_count = layer[i-1]
  
  if prev_count == 1:
    touri[i] = 1
    continue
  
  if count == 1:
    touri[i] = prev_count
    continue
  
  tmp = 0
  for j in range(count+1):
    tmp = tmp + cmb(count, j)
  touri[i] = tmp
    
ans = 1
for i in touri:
  ans = (ans * i) % 998244353
  
# print(layer)
# print(touri)
print(ans)

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)
    count = 1

    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections


n = int(input())

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


count_dict = collections.Counter(d)
result = 1
for i in range(1,max(d)+2):
    prenum = count_dict[i-1]
    nownum = count_dict[i]
    result *= prenum**nownum

result %= 998244353
 
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
L = [int(i) for i in input().split()]
LL = [0 for i in range(pow(10,5)+1)]
LLL = np.ones(pow(10,5)+1, dtype = "object")
 
for i in range(n):
  LL[L[i]] += 1
  
out = 1
for i in range(len(LL)-1):
  LLL[i+1] = pow(i+1, LL[i+1])

out = int(int(np.prod(LLL)) % 998244353)
if L[0] != 0 or L.count(0) != 1:
  out = 0
print(out)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
D_list=[int(thing) for thing in input().split(" ")]
maxx=max(D_list)
if D_list[0] !=0:
    print(0)
    exit()
C=collections.Counter(D_list)
if C[0] != 1:
    print(0)
    exit()

ret=1
for i in range(0,maxx):
    if maxx-i not in C:
        print(0)
        exit()
    if maxx-i==0:
        pass
    else:
        ret=ret*C[maxx-i-1]**C[maxx-i]

print(ret//998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

dic = [0] * n
for x in D:
    dic[x] += 1

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

ans = 1
for i in range(1, n):
    if dic[i] == 0:
        if sum(dic[i:]) == 0:
            break
        else:
            print(0)
            exit()

    ans *= dic[i-1] ** dic[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    k = list(c.keys())
    v = list(c.values())
    for i in range(1, len(v)):
        if k[i]-1 != k[i-1]:
            ans *= 0
        ans *= (v[i-1]**v[i]) % MOD
    print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter
fact = {}

def factorial(n):
    ans = 1
    for i in range(2, n + 1):
        ans = ans * i % mod
    return ans

def f(x):
    if x not in fact:
        ans = factorial(x) 
        fact[x] = ans
    else:
        ans = fact[x]
    return ans

def combinations_count(n, r):
    return f(n) // (f(n - r) * f(r))

def p(n,r):
    return f(n) // (f(n-r))

def h(n,r):
    return combinations_count(n+r-1, r)

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

ans = 0
mod = 998244353

if 0 not in d or (0 in d and d[0] != 1):
    print(0)
    exit()
if len(d) > 1 and 1 not in d:
    print(0)
    exit()

if 1 in d and d[1] == 0:
    print(d[0])
    exit()

ans = 1

for i in range(2,2+len(d)-2):
    if i not in d:
        print(0)
        exit()
    # print(ans, h(d[i-1], d[i]), d[i-1], d[i])
    
    ans = (ans * d[i-1]**d[i]) % mod
    # print(ans)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ans = 1
ans_ = 1
for i in range(len(D_)):
    temp = D_[i]
    if temp ==0:
        print(0)
        ans_ = 0
        break
    elif i > 0:
        ans *= D_[i-1] ** D_[i]
        ans %= 998244353
if ans_:
    print(ans)

Submission status: Wrong Answer

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

d.sort()
dd=[0]*10**5
for i in d:
    dd[i]+=1

ans=True
now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in dd[1:n-1]:
    if(i==0):
        ans=False
    now=now*(before**i) % 998244353
    before=i
    #print(now)

if(ans):
    print(now)
else:
    print("0")

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(1)
        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
    check = cnt
    
print(ans%998244353)

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

C = []

for i in range(N):
    temp = D.count(i)
    C.append(temp)
    D = [j for j in D if j != i]
    if D == []:
        break

Csize = len(C)

res = 1

for i in range(1,Csize):
    res = (res * C[i-1] ** C[i])

print(res)

Submission status: Wrong Answer

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

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

    l = 0
    r = 1

    if 0 not in Ds:
        print(0)
        return
    Ds.remove(l)
    if 0 in Ds:
        print(0)
        return
    c = []
    while len(Ds) > 0:
        l = l + 1
        cnt = Ds.count(l)
        c.append((r, cnt))
        r = cnt
        Ds = [x for x in Ds if x != l]
        
    ans = 1
    divider = 998244353
    for i, j in c:
        r = (i**j)%divider
        ans = ans%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 collections
import operator

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

D_dict = collections.Counter(D)
D_dict_sorted = sorted(D_dict.items(), key=operator.itemgetter(0))

# l = []
# for i in range(int(max(D))):
#     if D_dict_sorted[i][0] + 1 == D_dict_sorted[i+1][0]
#     l.append()

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

print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input().strip())
count = 1
array = list(map(int, input().strip().split(' ')))
if array[0] != 0:
    count = 0
else:
    for i in range(N):
        count = count * array[i]
ans = count % 998244353 
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = [int(_) for _ in input().split()]
c = Counter(d)
ans = 0
dmax = max(d)

if d[0] == 0 and c[0] == 1:
    ans = 1
    if dmax > 1:
        for i in range(2, dmax+1):
            ans *= c[i-1]**c[i]
        ans *= c[dmax]
print(ans)

Submission status: Wrong Answer

Solution code:
#b
n=int(input())
d=[int(i) for i  in input().split()]

import collections
c = collections.Counter(d)

m=998244353
ans=1
if d[0]!=0 or len(set(d))!=max(d)+1 or 0 in d[1:]:
    print(0)
else:
    for i in range(1,len(c)):
        ans = (ans* i**c[i] )%m
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

if D[0] != 0:
    print(0)
else:
    count = defaultdict(int)
    for d in D:
        count[d] += 1
    maxcount = max(count)
    S = 1
    for i in range(1, maxcount+1):
        S *= count[i-1]**count[i]
    M = int(S % 998244353)
    print(M)

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
    for i in range(2, iter+1):
        if c[i] == 0:
            return 0

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

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

Submission status: Wrong Answer

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

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

count = 1
dmax = max(d)
num_array = [0] * (dmax+1)

for i in range(len(d)):
    num_array[d[i]] += 1

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

for i in range(1, dmax+1):
    count *= i ** num_array[i]
    count %= 998244353
print(count)

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx < 2:
        if tree == 0:
            count = 0
    if tree == 0:
        count *= 0
    else:
        count *= tree_list[idx - 1]**tree
print(count)

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)

    count = c[0]
    ans = 0
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 1:
    for i in range(1,maxkey): 
        ans=ans*(dic[i]**dic[i+1])%MOD
    print(ans)
else:
    print(0)