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:
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 i == 0 and temp > 1:
        print(0)
        ans_ = 0
        break
    elif 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:
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
    if 0 in counter.values():
        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 sys

N = int(input())
D = [int(x) for x in sys.stdin.readline().split()]
 
D_list = list(set(D))
D_count = []
for d_ in D_list:
    D_count.append(D.count(d_))
if (D_list[-1] != len(D_list) - 1) | (D_count[0] != 1):
    print(0)
else:
    ans = 1
    for d1, d2 in zip(D_count[:-1], D_count[1:]):
        ans *= d1**d2
    print(ans % 998244353)

Submission status: Wrong Answer

Solution code:

import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0:
        continue
    else:
        ct *= b[i-1]**b[i]
if b[0] != 1:
    print(0)
else:
    print(ct)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if np.array(dic == 1).sum() == n:
    print(1)
    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 % 99824435)

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)
elif not all(D[1:-1]):
    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())
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
for i in li:
    box[i] += 1
count = 1

if len(box) > 1:
    for i in range(1, len(box)-1):
        count *= box[i] ** box[i+1]
else:
    count = 1
    
if box[0] != 1:
    count = 0

print(count % 998244353)

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 == 0:
        count *= tree
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
print(count%998244353)

Submission status: Wrong Answer

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

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

cnt = collections.Counter(D)

ans = 1
limit = max(cnt.keys()) + 1
for i in range(0, limit):
    if i == limit - 1:
        break
    n = cnt[i]
    r = cnt[i + 1]
    if n == 0 or r == 0:
        ans = 0
        break
    ans *= n ** r

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
deep,a,b,c = 0,1,0,1
for i in range(n):
  if s[i] == deep:
    b += 1
  elif i == n:
    c *= a ** b
  elif s[i] == deep + 1:
    c *= a ** b
    a = b
    b = 1
    deep += 1
  else:
    c = 0
    break
    
  if i == n-1:
    if s[i] == deep:
      c *= a ** b
      c = c % 998244353
    elif s[i] == deep + 1:
      c *= a ** b
      c = c % 998244353
    else:
      c = 0
      break  
print(c)

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 and c[max(D)] > 1:
        print(0)
        exit()

    print(count % MOD)




    

if __name__ == '__main__':
    main()

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) == 1:
            continue
        output *= pow(a.count(i-1),a.count(i),998244353)
    print(output)

Submission status: Wrong Answer

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


def ruijo(a, b, mod):
    for i in range(1000000):
        if b < 2 ** i:
            hoge = i
            break

    rui = []

    for i in reversed(range(hoge)):
        if b >= 2 ** i:
            rui.append(2 ** i)
            b -= 2 ** i

    x = 1

    for i in range(len(rui)):
        x *= (a ** rui[i]) % 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 *= ruijo(x[i-1],x[i],998244353)
    else:
        Sum *= x[i]

print(Sum)

Submission status: Wrong Answer

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

temp = 1
count = 1

if d[0] != 0 or d[1] != 1:
    print(0)
else:
    for i in (1, n-2):
        if d[i] == d[i+1]:
            count += 1
        else:
            if d[i] == 1:
                temp = 1 * count
                count = 1
            else:
                temp = temp * d[i] * count
                count = 1

    print(temp % 998244353)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))


if D[0] == 0 and ((len(D) - np.count_nonzero(D)) == 1):
    print(D[1:].prod() % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
elif 0 in a[1:]:
  print(0)
else:
  m=max(a)
  b=[0]*m
  for i in a[1:]:
    b[i-1]+=1
  if 0 in b:
    print(0)
  else:
    res=1
    print(b)
    for i in range(1,len(b)):
      res*=b[i-1]**b[i]
    print(res%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)

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

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.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]+1):
            if not dc[i]:
                count = 0
            else:
                count = ((count % mod) * (dc[i]**dc[i+1] % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

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)and(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:
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 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(0,max(D)+1):
        #print(cnt[i],tmp)
        c = (tmp**cnt[i]) % mod
        ans *= c
        tmp = cnt[i]
        ans = ans % mod
    print(ans % mod)

Submission status: Wrong Answer

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

L = sorted(set(D))
d = {}

F = (D[0] == 0) and (list(range(max(D) + 1)) == L)

if F:
    for i in D:
        d[i] = d.get(i, 0) + 1

s = 0
if F:
    for l in L[1:-1]:
        if l == 1:
            s = 1
        for i in range(d[l + 1]):
            s *= d[l]
            s %= 998244353

print(s)

Submission status: Wrong Answer

Solution code:
import sys

def main():
    N = int(input())
    D = map(lambda i: int(i), input().split(' '))
    ary = [0] * N

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

    # 続いてなかったらNG
    zero = False
    for i in range(len(ary)):
        if ary[i] != 0 and zero is True:
            print(0)
            sys.exit()
        if ary[i] == 0 and zero is False:
            zero = True

    # 距離0は頂点1だけ
    if ary[0] != 1:
        print(0)
        sys.exit()

    answer = 1
    for i in range(1, len(ary)):
        for j in range(ary[i]):
            answer = (answer * ary[i - 1]) % 998244353
    print(answer)

main()

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 and count[i] != 0):
        ans *= (count[i] ** count[i + 1]) % 998244353
    else:
        if (count[i] == 0 and count[i + 1] != 0):
            print(0)
            exit()

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

N=input()
D=map(int, sys.stdin.readline().split())
max_D=max(D)
if max_D>N-1:
    print 0
    quit()

C=Counter(D)

mod=998244353
if D[0]!=0:
    print 0
    quit()
else:
    ans=1
    for i in range(2,max_D+1):
        ans*=pow(C[i-1],C[i],mod)
        ans%=mod

print ans%mod

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))

num = len(D) - np.count_nonzero(D)

if len(D) - np.count_nonzero(D) == 1:
    print(D[1:].prod() % 998244353)
else:
    print(0)

Submission status: Wrong Answer

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

import collections
c = collections.Counter(d)
if c[0] != 1:
    print(0)
else:
    result = 1
    for i in range(1, len(c)):
        result *= c[i-1]**c[i]
        result = result%998244353
    print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
d=sorted(d)
if n==1:
    ans=0

for j in range(0,n-1):
    if d[j+1]-d[j]>1:
        ans=0
        
if d[0]!=0 or d[1]==0:
    ans=0
    
else:
    for i in range(1,n-1):
        if d[i]==d[i+1]:
            a+=1

        else:
            ans=ans*(b**a)
            b=a
            a=1
ans=ans*(b**a)
ans=ans%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def q1(n):
    return (n - 1) // 2


def q2(n, D):
    MAXINT = 998244353
    counts = np.sum(D == np.arange(n)[:, None], axis=1)
    idx = np.where(counts == 0)[0]
    minidx = np.min(idx)
    if len(idx) != n - minidx:
        return 0
    return int(np.prod([counts[i] ** counts[i + 1] for i in range(minidx)])) % MAXINT


if __name__ == '__main__':

    # A 問題
    # n = int(input())
    # print(q1(n))

    # B 問題
    # n = int(input())
    # D = np.asarray(list(map(int, input().split())))
    # n = 4
    # D = np.array([0, 1, 1, 2])
    # D = np.array([1, 1, 1, 1])
    n = 7
    D = np.array([0, 3, 2, 1, 2, 2, 1])
    print(q2(n, D))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
a=sorted([int(i) for i in input().split()])
# n=10**6
# a=[0]+[(i+2)//2 if i%2==0 else i//2+1 for i in range(n-1)]
c=Counter(a)
ans=1
# if c[0]!=1:
#     print(0)
#     quit()

# for i in range(n-1):
#     if a[i+1]-a[i]>1:
#         print(0)
#         quit()

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


print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())                                                                                                   
                                                                                                                   
d = list(map(int, input().split()))                                                                                
                                                                                                                   
ans = 1                                                                                                            
                                                                                                                   
for i in d:                                                                                                        
    ans *= i if i != 0 else 1                                                                                      
                                                                                                                   
print(ans%998244353 if ans != 1 else 0)

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)and(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(counts)
        #print(int(counts%998244353))
        
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
from collections import Counter
c = Counter([int(i) for i in input().split()])

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

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

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    datas = [_ for _ in range(max(A) + 1)]
    counts = [0] * len(datas)
    for i in range(max(A) + 1):  # i = 0 ~ max(A)
        if i not in A:
            print(0)
            exit()
        else:
            counts[i] = A.count(i)
    return datas, counts

def power_func(a, n, p):
    bi = str(format(n, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res

INF = 998244353

N = int(input())
D = list(map(int, input().split()))
D_datas, D_counts = ContinueCnt(D)
# print(D_datas, D_counts)  # for debug

# first check zero
if D_counts[0] != 1:
    print(0)
    exit()

ans = 1
# check 1 ~ max(D)
for i in range(1, max(D_datas) + 1):
    ans *= power_func(D_counts[i - 1], D_counts[i], INF)
    # print("now = ", ans)  # for debug

print(ans % INF)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
for i in li:
    box[i] += 1
count = 1

if len(box) > 1:
    for i in range(2, len(box)):
        count *= box[i-1] ** box[i]
else:
    count = 1
    
if box[0] != 1:
    count = 0

print(count % 998244353)

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)
else:
    mod = 998244353
    ans = 1
    distance = 0
    prev = 1
    now = 0
    for i in range(len(D)):
        if D[i] == distance:
            now += 1
        elif D[i] == distance + 1:
            ans = (ans % mod) * (prev ** now % mod) % mod
            prev = now+0
            now = 1
            distance += 1
        else:
            ans = 0
            break
    else:
        ans = (ans % mod) * (prev ** now % mod) % mod
    
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
N = int(input())
D = [int(i) for i in input().split()]
c = collections.Counter(D)
#print(c)

if D[0] != 0:
    val = 0
else:
    tmp = 1
    for n in range(1, N):  #1からN-1
        tmp = tmp * (n**c[n])
    val = tmp % 998244353
print(val)

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

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

import collections
c = collections.Counter(d)
if c[0] != 1:
    print(0)
else:
    result = 1
    for i in range(1, len(c)):
        result *= c[i-1]**c[i]
    print(result%998244353)

Submission status: Wrong Answer

Solution code:
mod = 998244353
n = int(input())
import collections
dat = list(map(int, input().split()))
c = collections.Counter(dat)
ma = max(c)
#print(c)
res = 1
#print(c)

for i in range(ma ):
    #print("{0} ^ {1}".format(i, i+1))
    #print("={0} ^ {1}".format(c[i], c[i+1]))
    res *= c[i] ** (c[i+1])
    res %= mod
if dat[0] != 0:
    print(res)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import math
import collections

#n = int(input())
d = list(map(int,input().split()))
n = len(d)
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]==1:
    ans = 1
    for i in range(len(dict(cnt))-1):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      #print(val_1,val_2)
      ans *= (val_1**val_2)
    print(ans%MOD)
  else:
    print(0)
except KeyError:
  print(0)

Submission status: Wrong Answer

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

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

cnt = collections.Counter(D)

ans = 1
limit = max(cnt.keys()) + 1
for i in range(0, limit):
    if i == limit - 1:
        break
    n = cnt[i]
    r = cnt[i + 1]
    if n == 0 or r == 0:
        ans = 0
        break
    ans *= n ** r

print(ans)

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

    Ds.sort()
    if Ds.count(0) != 1:
        print(0)
        return
    Ds.remove(0)

    l = 0
    r = 1
    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 numpy as np

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

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

if len(ll) == 1:
    print(ll[0])
    exit()

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:
import math
import collections

#n = int(input())
d = list(map(int,input().split()))
n = len(d)
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]==1:
    ans = 1
    for i in range(len(dict(cnt))-1):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      print(val_1,val_2)
      ans *= (val_1**val_2)
    print(ans%MOD)
  else:
    print(0)
except KeyError:
  print(0)

Submission status: Wrong Answer

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

import collections
c=collections.Counter(D)
ans=1

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)
  for i in range(2,N):
    ans*=(c[i-1]**c[i])
  print(ans)

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 and count[i] != 0):
        ans *= (count[i] ** count[i + 1]) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
deep,a,b,c = 0,1,0,1
for i in range(n):
  if s[i] == deep:
    b += 1
  elif i == n:
    c *= a ** b
  elif s[i] == deep + 1:
    c *= a ** b
    a = b
    b = 1
    deep += 1
  else:
    c = 0
    break
    
  if i == n-1:
    if s[i] == deep:
      c *= a ** b
    elif s[i] == deep + 1:
      c *= a ** b
    else:
      c = 0
      break  
print(c%998244353)

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 range(1,max+1):
    if(dd[i]==0):
        ans=False
    now=now*(before**dd[i]) % 998244353
    before=dd[i]
    #print(i)

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

Submission status: Wrong Answer

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

    print(calc(d, n))


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


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
A = list(map(int,input().split()))
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

ans = 1
bef = A.count(1)
if A[0] > 0 or A.count(0) > 1:
    print(0)
else:
    for i in range(2,max(A)+1):
        cnt = A.count(i)
        ans *= (bef**cnt)%mod
        bef = cnt
    print(ans)

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
    if 0 in counter.values():
        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:
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)
elif ans > 1:
    print(1)
else:
    print(0)

Submission status: Wrong Answer

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

ans = 1
ans_li = [0 for i in range(n)]
count = 0

for i in range(n):
    ans_li[li[i]] += 1

if not ans_li[0] == 1:
    print(0)
    exit()

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

for i in range(n-1):
    if ans_li[i] == 0 and (not ans_li[i+1] == 0):
        print(0)
        exit()

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 = []

Dmax = max(D)

for i in range(Dmax+1):
    temp = D.count(i)
    C.append(temp)

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:
n = int(input())
d = list(map(int, input().split()))

import collections
c = collections.Counter(d)
if c[0] != 1:
    print(0)
else:
    result = 1
    for i in range(1, len(c)):
        result *= c[i-1]**c[i]
    print(result)

Submission status: Wrong Answer

Solution code:
a=int(input())
d=[int(x) for x in input().split()]
d.sort()
z=max(d)
w=d.count(0)
if d[0]==0 and w==1:
  n=1
  for i in range(z-1):
    x=i+2
    r=d.count(x-1)
    q=d.count(x)
    n=n*(r**q) 
  print(n%998244353)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))

if not D[0] == 0:
    print(0)
else:
    print(D[1:].prod() % 998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def ruijo(a, b, mod):
    for i in range(10000):
        if b < 2 ** i:
            hoge = i
            break

    rui = []

    for i in reversed(range(hoge)):
        if b >= 2 ** i:
            rui.append(2 ** i)
            b -= 2 ** i

    x = 1

    for i in range(len(rui)):
        x *= (a ** rui[i]) % 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 *= ruijo(x[i-1],x[i],998244353)
    else:
        Sum *= x[i]

print(Sum)

Submission status: Wrong Answer

Solution code:
import collections

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

l = collections.Counter(D)  

for i in range(N):
  if l[i] != 0 and i != N:
      ans *= l[i] ** l[i+1]

if D[0] != 0:
  print(0)
else:
  print(ans%998244353)

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
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
print(count%998244353)

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)and(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:
def nCr(n, r):
    import math
    # nCrのr>nは組み合わせが存在しないので0を返す
    # raiseすべきのこともあるかも
    if r > n:
        return 0
    return math.factorial(n) // ((math.factorial(n - r) * math.factorial(r)))
mod = 998244353
n = int(input())
import collections
dat = list(map(int, input().split()))
c = collections.Counter(dat)
ma = max(c)
#print(c)
res = 1
#print(c)

for i in range(ma ):
    #print("{0} ^ {1}".format(i, i+1))
    #print("={0} ^ {1}".format(c[i], c[i+1]))
    res *= c[i] ** (c[i+1])
    res %= mod
print(res)

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(map(int, 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)