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


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 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]
 
e = 0
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1
if D[0] != 0 or e == 1:
  print(0)
elif N == 1:
  print(1)
elif N == 2 and D[1] == 1:
  print(1)
else:
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    N = II()

    if N % 2 == 0:
        print((N//2)-1)
    else:
        print(N//2)
    return

# B


def B():
    N = II()
    D = LI()
    if D[0] != 0:
        print(0)
        return

    if D.count(0) != 1:
        print(0)
        return
    ans = [0]*(N)
    answer = 1

    for i in range(1, N):

        ans[D[i]] += 1
    count = ans[1]
    for x in range(1, N-2):
        a = ans[x]
        b = ans[x+1]
        if a == 0:
            print(0)
            return
        answer = answer * (a**b)
        count += b
        if count == N-1:
            break

    print(answer)

    return

# C


def C():
    N = II()
    A = LI()
    B = LI()

    L = []
    count = 0
    for i in range(2, int(sqrt(N)+2)):
        if N % i == 0:
            L.append(N/i)
            count = 1
    if count == 0:
        print(N-1)
    else:
        print(int(L[-1]-2+(N/L[-1])))

    return

# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

if d[0] != 0 or d.count(0) != 1:
    print(0)
else:
    ans = 1
    nx = 0
    pre = 1
    cnt = 0
    for i in range(n):
        if d[i] == nx:
            cnt += 1
        else:
            if d[i] == nx + 1:
                ans = ans * pre ** cnt
                pre = cnt
                cnt = 1
                nx += 1
            else:
                ans = 0
                break
    ans = ans * pre ** cnt
    print(ans%wari)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
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[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    # 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= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        ans = 1
        # for k, g in groupby(ar):
        #         ans *= int(k) ** len(list(g))
        print(np.prod(ans_ar) % 998244353)

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

Submission status: Wrong Answer

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

initial = d[0]
maximum = max(d)

l = [0] * (maximum+1)
l[initial] += 1
for i in range(1, N):
    # if d[i] <= initial:
    #     print(0)
    #     exit()
    l[d[i]] += 1

ans = 1
for i in range(1, maximum):
    if l[i] == 0:
        print(0)
        exit()

    ans *= l[i] ** l[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=sorted(list(map(int,input().split())))
c=Counter(d)
c=sorted(c.items(),key=lambda x:x[0])
if c[0]!=(0,1):
    print(0)
    exit()
ans=1
check=1
for i in range(1,len(c)):
    if c[i][0]!=check:
        print(0)
        exit()
    check+=1
    ans*=c[i-1][1]**c[i][1]
    ans%=998244353
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
c=[0 for i in range(max(d)+1)]
for x in d:
  c[x]+=1
if d[0]!=0 or (0 in c):
  print(0)
  exit()
p=1
for x in c:
  ans*=p**x
  p=x
print(ans%998244353)

Submission status: Wrong Answer

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

elif n == 2:
  if l[0] ==0 and l[1] == 1:
    print(1)
  else:
    print(0)

else:
  if l[0] != 0:
    print(0)
  else:
    a = [0]*n
    for i in range(n):
      a[l[i]] += 1

    if a[0] != 1:
      print(0)
    else:
      for i in range(n-1):
        if a[i]!=0 and a[i+1]!=0:
          ans = ans * (a[i]**a[i+1])
        else:
          break

      print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input().strip())
array = list(map(int, input().strip().split(' ')))
if array[0] != 0:
    count = 0
elif 0 in array and array[0] != 0:
    count = 0

else:
  count = 1
for i in range(N//2 + 1):
    if array[i] != 0:
        count = count * array[i]
    if array[N-i-1] !=0:
        count  = count * array[N-i-1]
if N % 2 !=0:
    if array[(N//2)] != 0:
        count = count // array[(N//2)]
            
ans = count % 998244353 
print(ans)

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]
 
e = 0
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1
if D[0] != 0 or e == 1:
  print(0)
elif N == 1:
  print(1)
else:
  print(ans%998244353)

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(n-1):
    ans *= ans_li[i] ** ans_li[i+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:
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 % MOD


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

occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
t = 1
for i in range(1, N+5):
    if occ[i] == 0:
        break
    t += occ[i]
    cur *= pow(occ[i - 1], occ[i])
    cur %= MOD

if t == N - 1:
    print(cur % MOD)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
ans = 0
if D[0] == 0 and D.count(0) == 1:
    ans = 1
    for i in range(2, max(D)+1):
        ans = ans * (D.count(i-1)**D.count(i))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
k = [0]*100005
for i in d:
    k[i] += 1
c = 1
for i in range(d[-1]):
    for j in range(k[i+1]):
        c *= k[i]
        c %= 998244353
if (k[0] >= 2):
    print(0)
else:
    print(c)

Submission status: Wrong Answer

Solution code:
import collections

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

cnt = collections.Counter(D)

if D[0] != 0:
    ans = 0
else:
    ans = 1
    for i in range(1, max(D)+1):
        if cnt[i] == False:
            ans = 0
            break
        else:
            ans *= i ** cnt[i]

print(ans%998244353)

Submission status: Wrong Answer

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

a.sort()
if a[0] != 0 or a[1] != 1:
  print 0
  exit(0)

ans = 1
old = 1
now = 1
c = 0

for q in range(1,len(a)):
  ans %= 998244353

  if now != a[q]:
    if now+1 != a[q]:
      print 0
      exit(0)
    else:
      ans = ans * pow(old,c,998244353)
      old = c
      c = 1
      now = a[q]
  else:
    c += 1
ans = ans * pow(old,c,998244353)

ans %= 998244353
print ans

Submission status: Wrong Answer

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

import numpy as np

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

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

    l = 0
    r = 1
    c = []
    while Ds.size > 0:
        l = l + 1
        cnt = Ds[Ds==l].size
        c.append((r, cnt))
        r = cnt
        Ds = Ds[cnt:]
        
    ans = 1
    divider = 998244353
    for i, j in c:
        r = (i**j)%divider
        ans = (ans*r)%divider
    
    print(ans)

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter


def nCr(n, r):
    nn = 1
    for _ in range(r):
        nn *= n
        n -= 1
    rr = 1
    for _ in range(r):
        rr *= r
        r -= 1
    return nn // rr


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

ans = counter[0]
for i in range(1, d[-1] + 1):
    if counter[i] == 0:
        ans = 0
        break
    if counter[i - 1] > 1:
        m, n = counter[i - 1], counter[i]
        c = 0
        if m > n:
            for j in range(0, n):
                c += nCr(m, n - j)
        else:
            c = m ** n
        ans *= c


print(ans % M)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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] % MOD, n=counter[i] % MOD, 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 = [int(x) for x in input().split()]
dis = 98244353
 
if D[0] != 0:
  print(0)
  exit()
D.sort()
if D[1] == 0:
  print(0)
  exit()
ans = 1
c = 1
num = 1
for i in range(1,len(D)):
  if D[i] == D[i-1]:
    c += 1
  else:
    ans = ans * num**c
    num = c
    c = 1
  if i == len(D)-1:
    ans = ans * num**c

  

  #print(ans,num,c) 

print(ans%dis)

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))%998244353 
  print(n)
else:
  print(0)

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)

def is_connected(distance):
    """
    >>> is_connected([0, 1, 2, 3])
    True
    >>> is_connected([0,1, 0, 1])
    False
    >>> is_connected([0, 1, 1, 0, 0, 0])
    True
    """
    is_zero = False
    for d in distance[1:]:
        if is_zero and d > 0:
            return False
        if d == 0:
            is_zero = True
    return True


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

Submission status: Wrong Answer

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

if D_list.count(0) == 1:
    res = 1
    for i in range(0, max(D_list)):
        res *= D_list.count(i) ** D_list.count(i+1)

    print(res % 998244353)
else:
    print(0)

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):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

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

if e < 0:
    print(0)
else:
    print(result)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
# MOD = 10**9+7
MOD = 998244353

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

Submission status: Wrong Answer

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

if d[0] != 0 or d.count(0) != 1:
    print(0)
else:
    ans = 1
    nx = 1
    pre = 1
    cnt = 0
    for i in range(1, n):
        if d[i] == nx:
            cnt += 1
        else:
            if d[i] == nx + 1:
                ans = ans * pre ** cnt
                pre = cnt
                cnt = 1
                nx += 1
            else:
                ans = 0
                break
    ans = ans * pre ** cnt
    print(ans%wari)

Submission status: Wrong Answer

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

dict = {}
for i in range(N):
    if list[i] in dict.keys():
        dict[list[i]] += 1
    else:
        dict.setdefault(list[i], 1)

max = max(dict)

try:
    for i in range(1,max+1):
        ans = (ans * (dict[i-1] ** dict[i])) % 998244353
    if dict[0] != 1:
        ans = 0
except KeyError:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
b=a.pop(0)
if b!=0:print(0);exit()
import collections
d=collections.Counter(a)
e=[[i,j] for i,j in d.items()]
e.sort()
ans=1
d1=[i[0] for i in e]
d2=[i[1] for i in e]
for i,I,j,J in zip(d1,d1[1:],d2,d2[1:]):
    if i+1!=I:
        print(0)
        exit()
    ans*=j**J
print(ans)

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    datas = [_ for _ in range(max(A) + 1)]
    counts = [0] * len(datas)
    if set(datas) != set(A):
        print(0)
        exit()
    for j in range(max(A) + 1):
        counts[j] = A.count(j)
    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)

# 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)
    ans %= INF

print(ans % INF)

Submission status: Wrong Answer

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

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

if d[0] > 0:
        print(0)
        exit()
else:
        #グラフ作れるかチェック
        # for i in range(len(setD)-1):
        #         c[setD[i]]
        c = Counter(d)
        for s in setD:
                ans *= math.factorial(c[s])
                nodeMulti *= c[s]
        nodeMulti //= setD[-1]
        # ans *= nodeMulti
        print(ans%998244353)

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)+1):
    prenum = count_dict[i-1]
    nownum = count_dict[i]
    result *= prenum**nownum
    #result %= 998244353
 
print(result)

Submission status: Wrong Answer

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

sum = 1
if d[0] == 0 and d.count(0)==1:
  for i in range(n):
    a = d.count(i)
    b = d.count(i+1)
    if b != 0:
      c = a**b
      sum = sum*c
    
if d[0] == 0 and d.count(0)==1:
  print(sum)
else:
  print("0")

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]
 
e = 0
for i in range(N-1):
  if l[i] == 0 and l[i] != 0:
    e = 1
if D[0] != 0 or e == 1:
  print(0)
elif N == 1:
  print(1)
else:
  print(ans%998244353)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
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
    hoje = 1
    for i in range(len(rui)):
        for j in range(rui[i]):
            hoje = (hoje * a) % mod 

        x *= hoje
    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:
def main():
    import collections
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = list(map(int, input().split()))
    ans = 1
    if d[0] != 0:
        print(0)
    else:
        c = collections.Counter(d)
        if 1 in c.keys():
            ans *= c[1]
        for i in range(2, n):
            if i in c.keys():
                ans = (ans ** c[i]) * c[i]
                ans %= 998244353
                if not (i + 1 in c.keys()):
                    print(ans)
                    exit()
            else:
                print(0)
                exit()
        if ans == 1 and (1 in c.keys()):
            ans = c[1]
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

n = int(input())
dd = list(map(int, input().split()))
dd.sort()
ans = 1
first = dd.pop(0)

if first != 0:
    print(0)
    exit()

for i in range(n-1):
    ans *= dd[i]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
D0, D1 = D[0], D[1:]
if D0 == 0:
    ans = reduce(mul, filter(lambda x: x!= 0, D1))
    print(ans % M)
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)%998244353
    check = cnt
    
print(ans%998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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)
can = True

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


if dat[0] != 0:
    print(0)
elif can is False:
    print(0)
else:
    print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
N = int(stdin.readline().rstrip())
_A = stdin.readline().rstrip().split()
A = [int(s) for s in _A]

Max = max(A)
Tes = True
for el in range(Max + 1):
    if (not el in A):
        Tes = False

res = 1
for el in range(1, Max + 1):
    res *= (A.count(el - 1) ** A.count(el))
if (Tes):
    print(res)
else:
    print('0')

Submission status: Wrong Answer

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

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
if d[-1]!=d[-2]:
  ans*=count
  
if d[0]==0:
  print(ans%998244353)
elif d[0]!=0:
  print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
A = collections.Counter(D)
result = 1
for i in range(max(D)):
    result *= A[i] ** A[i+1]
print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
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[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    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= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        ans = 1
        # for k, g in groupby(ar):
        #         ans *= int(k) ** len(list(g))
        print(np.cumprod(ans_ar)[-1] % 998244353)

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

Submission status: Wrong Answer

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

import numpy as np

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

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

    l = 0
    r = 1
    c = []
    while len(Ds) > 0:
        l = l + 1
        cnt = Ds[Ds==l].size
        c.append((r, cnt))
        r = cnt
        Ds = Ds[cnt:]
        
    ans = 1
    divider = 998244353
    for i, j in c:
        r = (i**j)%divider
        ans = (ans*r)%divider
    
    print(ans)

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

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

Submission status: Wrong Answer

Solution code:


def solve():
    N = int(input())
    D = [int(i) for i in input().split()]
    # 対象となる木のパターン数のチェック
    mD = max(D)
    nD = [0] * (mD + 1)
    for d in D:
        nD[d] += 1
    count = nD[0]
    for i in range(2, len(nD)):
        count *= nD[i - 1] ** nD[i]
        count = count % 998244353
    print(count)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

print(ans % mod)