Problem:


Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

Solution code:
from itertools import groupby
inputs = open(0).readlines()
n = int(inputs[0])
*D, = map(int, inputs[1].split())
D.sort()
mod = 998244353

keys = [k for k, g in groupby(D)]
nodes = [len(list(g)) for k, g in groupby(D)]

if nodes[0] != 1:
    print(0)
else:
    patterns = [1]
    for i, (k, n0, n1) in enumerate(zip(keys, nodes, nodes[1:])):
        if i != k:
            print(0)
            break
        patterns.append(patterns[i] * pow(n0, n1, mod) % mod)
    else:
        print(patterns[-1])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int


def solve(N: int, D: "List[int]"):
    from collections import Counter
    c = Counter(D)

    x = sorted(list(set(D)))
    if D[0] != 0 or any([0 >= i for i in D[1:]]):
        print(0)
        exit()

    # if D[0] != 0 or len(x) <= 1 or max(x) - min(x) + 1 != len(x):
    #     print(0)
    #     exit()

    ans = 1
    for i in range(2, N):
        if c[i - 1] >= 2:
            ans *= pow(c[i - 1], c[i]) % MOD

    print(ans % MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by
# using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int


def solve(N: int, D: "List[int]"):
    from collections import Counter
    c = Counter(D)

    x = sorted(list(set(D)))
    if D[0] != 0 or len(x) <= 1 or max(x) - min(x) + 1 != len(x):
        print(0)
        exit()

    ans = 1
    for i in range(2, N):
        if c[i - 1] >= 2:
            ans *= pow(c[i - 1], c[i]) % MOD

    print(ans % MOD)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by
# using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    distance = list(map(int, input().split()))
    count_distance = {}
    for d in distance:
        if d in count_distance:
            count_distance[d] += 1
        else:
            count_distance[d] = 1
    count_distance = sorted(count_distance.items(), key=lambda x: x[0])
    answer = 0
    mod = 998244353
    if distance[0] == 0 and count_distance[0] == 1:
        answer = 1
        for i in range(1, len(count_distance)):
            if count_distance[i][0] == count_distance[i - 1][0] + 1:
                answer = (answer * pow(count_distance[i - 1][1], count_distance[i][1], mod)) % mod
            else:
                answer = 0
                break
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    distance = list(map(int, input().split()))
    count_distance = {}
    for d in distance:
        if d in count_distance:
            count_distance[d] += 1
        else:
            count_distance[d] = 1
    count_distance = sorted(count_distance.items(), key=lambda x: x[0])
    answer = 0
    mod = 998244353
    if distance[0] == 0:
        answer = 1
        for i in range(1, len(count_distance)):
            if count_distance[i][0] == count_distance[i - 1][0] + 1:
                answer = (answer * pow(count_distance[i - 1][1], count_distance[i][1], mod)) % mod
            else:
                answer = 0
                break
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    length = int(input())
    distance = list(map(int, input().split()))
    count_distance = {}
    for d in distance:
        if d in count_distance:
            count_distance[d] += 1
        else:
            count_distance[d] = 1
    count_distance = sorted(count_distance.items(), key=lambda x: x[0])
    answer = 0
    mod = 998244353
    if distance[0] == 0:
        answer = 1
        for i in range(2, len(count_distance)):
            if count_distance[i][0] == count_distance[i - 1][0] + 1:
                answer = (answer * pow(count_distance[i - 1][1], count_distance[i][1], mod)) % mod
            else:
                answer = 0
                break
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


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

cnt = [0 for i in range(N)]

flg = 1
if D[0]!=0:
    flg = 0
for i in range(N):
    if D[i]==0 and i!=0:
        flg = 0
    else:
        cnt[D[i]] += 1
print(cnt)
ans = 1
mod = 998244353
flg2 = 1
for i in range(1,N):
    if cnt[i]>0 and flg2:
        ans *= cnt[i-1]**cnt[i]
        ans %= mod
    elif cnt[i]>0 and (not(flg2)):
        flg = 0
    else:
        flg2 = 0
print(ans*flg)

Submission status: Wrong Answer

Solution code:
def powmod(n: int, p: int, M: int) -> int:
    ans = 1
    for _ in range(p):
        ans *= n
        ans %= M
    return ans

def solve():
    N = int(input())

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

    node = [0] * N

    for distance in distances:
        node[distance] += 1

    ans = 1
    MOD = 998244353

    index = 0
    for i, n in enumerate(reversed(node)):
        if n != 0:
            index = len(node)-1 - i
            break
    #print(f'{index=}')
    for n in node[:index]:
        if n == 0:
            print(0)
            return
            

    if node[0] != 1:
        print(0)
    else:
        previous = node[1]
        for i in range(2,N):
            now = node[i]
            ans = ans * powmod(previous, now, MOD) % MOD
            previous = now
        print(ans)
    
solve()

Submission status: Wrong Answer

Solution code:
def powmod(n: int, p: int, M: int):
    ans = 1
    for _ in range(p):
        ans *= n
        ans %= M
    return ans


N = int(input())

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

node = [0] * N

for distance in distances:
    node[distance] += 1

ans = 1
MOD = 998244353

if node[0] != 1:
    print(0)
else:
    previous = node[1]
    for i in range(2,N):
        now = node[i]
        ans = ans * powmod(previous, now, MOD) % MOD
        previous = now
    print(ans)

Submission status: Wrong Answer

Solution code:
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    d = list(map(int,ipti().split()))
    d_max = max(d)

    if d[0] != 0:
        print(0)
    else:
        c = Counter(d)
        ans = 1
        for i in range(d_max):
            if c[i] == 0:
                ans = 0
                break
            else:
                ans *= c[i] ** c[i+1]
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    d = list(map(int,input().split()))
    MOD = 998244353
    
    use = [0 for _ in range(max(d)+1)]
    for num in d:
        use[num] += 1
    if use[0] != 1:
        print(0)
    else:
        ans,pa = 1,1
        for num in use:
            ans *= pow(pa,num,MOD)
            ans %= MOD
            pa = num
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def main():
    N = int(input())
    d = list(map(int,input().split()))
    MOD = 998244353
    
    use = [0 for _ in range(max(d)+1)]
    for num in d:
        use[num] += 1
    
    ans,pa = 1,1
    for num in use:
        ans *= pow(pa,num,MOD)
        ans %= MOD
        pa = num
        
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
count=collections.Counter(arr)
if count[0]!=1:
  print(0)
else:
  ans=1
  for i in range(1,n):
    ans*=pow(count[i-1],count[i],mod)
    ans%=mod
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
l=len(set(arr))
m=max(arr)
if l!=m+1:
  print(0)
else:
  count=collections.Counter(arr)
  ans=1
  for i in range(1,n):
    ans*=pow(count[i-1],count[i],mod)
    ans%=mod
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
count=[0]*(n)
for d in arr:
  count[d]+=1
ans=1
for i in range(1,n):
  ans*=count[i-1]**count[i]
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
l=len(set(arr))
m=max(arr)
if l!=m+1:
  print(0)
else:
  dic=collections.defaultdict(int)
  for d in arr:
    dic[d]+=1
  ans=1
  for i in range(1,n):
    ans*=pow(dic[i-1],dic[i],mod)
    ans%=mod
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
m=max(arr)
dic=collections.defaultdict(int)
for d in arr:
  dic[d]+=1
ans=1
for i in range(1,m+1):
  ans*=pow(dic[i-1],dic[i],mod)
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

mod=998244353
n=int(input())
arr=list(map(int,input().split()))
dic=collections.defaultdict(int)
for d in arr:
  dic[d]+=1
ans=1
for i in range(1,n):
  ans*=pow(dic[i-1],dic[i],mod)
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

for e,(k,v) in enumerate(c.items()):
    if e==0:
        if k!=0 or v!=1:
            ans = 0
            break
        else:
            pre_v = v
            ans = v
    elif e!=k or v==0:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

for e,(k,v) in enumerate(c.items()):
    if e==0:
        if k!=0 or v!=1:
            ans = 0
            break
        else:
            pre_v = v
            ans = v
    elif e!=k:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre_v = 1
for e,(k,v) in enumerate(c.items()):
    if e==0 and (k!=0 or v!=1):
        ans = 0
        break
    elif e!=k:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre_v = 1
for e,(k,v) in enumerate(c.items()):
    if e==0 and k!=0:
        ans = 0
        break
    elif e!=k:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre_v = 1
for e,(k,v) in enumerate(c.items()):
    print(e,k,v)
    if e==0 and k!=0:
        ans = 0
        break
    elif e!=k:
        ans = 0
        break
    else:
        ans = ans*pow(pre_v, v, mod)%mod
        pre_v = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre = 1
for e,(k,v) in enumerate(c.items()):
    if e==0 and k!=0:
        ans = 0
        break
    else:
        ans = ans*pow(pre, v, mod)%mod
        pre = v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
lst = list(map(int,input().split()))
mod = 998244353
c = dict(Counter(lst))
c = dict(sorted(c.items(), key=lambda x:x[0]))

ans = 1
pre = 1
for e,(k,v) in enumerate(c.items()):
    if e==0 and k!=0:
        ans = 0
        break
    else:
        ans *= pre**v
        pre = v
        ans %= mod
print(ans%mod)

Submission status: Wrong Answer

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

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

far = 0

cnt = [0 for i in range(N)]

for d in D:
    cnt[d] += 1
    far = max(d, far)

ans = 1

for i in range(1, far):
    ans *= cnt[i] ** cnt[i + 1]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
for i in range(len(cnt)+1):
    ans *= pow(cnt[i], cnt[i+1], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

ans = 1
for i in range(len(cnt)+1):
    ans *= pow(cnt[i], cnt[i+1], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

max_cnt = max(cnt)
ans = 1
for i in range(max_cnt+1):
    ans *= pow(cnt[i], cnt[i+1], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

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

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

d.sort()

import collections
c = collections.Counter(d)

if c[0] != 1:
    print(0)
    exit()
ans=1
for i in range(1,d[-1]+1):
    if c[i] == 0:
        print(0)
        exit()
    ans*=(c[i-1]**c[i])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
mod = 998244353
if a[0] != 0:
  print(0)
  exit()
ans = 1
c = Counter(a)
cls = list(c.items())
cls.sort()
if cls[0][1] != 1:
  print(0)
  exit()
for i in range(2,len(cls)):
  ans = ans*cls[i-1][1]**cls[i][1]%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
mod = 998244353
if a[0] != 0:
  print(0)
  exit()
ans = 1
c = Counter(a)
cls = list(c.items())
cls.sort()
if cls[0][1] != 1:
  print(0)
  exit()
for i in range(1,len(cls)):
  ans = ans*cls[i-1][1]%mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
rng = 100100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod

n = int(input())
a = list(map(int,input().split()))
mod = 998244353
if a[0] != 0:
  print(0)
  exit()
ans = 1
c = Counter(a)
cls = list(c.items())
cls.sort()
if cls[0][1] != 1:
  print(0)
  exit()
for i in range(1,len(cls)):
  ans = ans*cmb(cls[i-1][1],cls[i][1])%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 998244353
if a[0] != 0:
  print(0)
  exit()
ans = 1
for i in range(1,n):
  ans = ans*a[i]%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mod = 998244353
if a[0] != 0:
  print(0)
  exit()
ans = 1
for i in range(1,n):
  ans = ans*a[i]%mod
print(mod)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
if D[0] != 0:
    print(0)
else:
    dc1 = Counter(D[1:])
    dc = [0 for i in range(max(D))]
    for k,v in dc1.items():
        dc[k-1] = v
    ans = 1
    for i in range(1,len(dc)):
        if dc[i] == 0:
            ans = 0
            break
        ans = (ans*(dc[i-1]**dc[i]))%mod
    print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
D = list(map(int,input().split()))
from collections import Counter
if D[0] != 0:
    print(0)
else:
    dc1 = Counter(D[1:])
    dc = [0 for i in range(max(D))]
    for k,v in dc1.items():
        dc[k-1] = v
    now = 1
    ans = 1
    for i in range(len(dc)):
        if dc[i] == 0:
            ans = 0
            break
        ans = (ans*(dc[i-1]**dc[i]))%mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
d=list(map(int,input().split()))
if set(d)-set(range(max(d)+1))!=0:
  print(0)
  exit()
l=sorted(collections.Counter(d).items(),key=lambda x:x[0])
ans=1
x=998244353
for i,j in zip(l[::-1][:-1],l[::-1][1:]):
  down,numDown=i[0],i[1]
  up,numUp=j[0],j[1]
  ans*=numUp**numDown
  ans=ans%x
  #print("{0}:{1},{2}:{3}".format(down,numDown,up,numUp),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
d=list(map(int,input().split()))
if 0 not in d or len(set(d))!=max(d)+1:
  print(0)
  exit()
l=sorted(collections.Counter(d).items(),key=lambda x:x[0])
ans=1
x=998244353
for i,j in zip(l[::-1][:-1],l[::-1][1:]):
  down,numDown=i[0],i[1]
  up,numUp=j[0],j[1]
  ans*=numUp**numDown
  ans=ans%x
  #print("{0}:{1},{2}:{3}".format(down,numDown,up,numUp),ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
count = [0]*(10**5+1)
L = list(map(int,input().split()))
M = max(L)
ans = 0
for i in range(n):
  count[L[i]] += 1
for i in range(M+1):
  if count[i] == 0:
    ans = 0
    break
  else:
    if i == 0:
      if count[i] != 1:
        ans = 0
        break
      else:
        ans = 1
    else:
      ans = ans*((count[i-1]**count[i])%mod)
      ans = ans%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
count = [0]*(10**5+1)
L = list(map(int,input().split()))
M = max(L)
ans = 0
for i in range(n):
  count[L[i]] += 1
flag = True
for i in range(M+1):
  if count[i] == 0:
    flag = False
    break
  else:
    if i == 0:
      if count[i] != 1:
        flag = False
        break
      else:
        ans = 1
    else:
      ans = ans*(count[i-1]**count[i])%mod
      ans = ans%mod
if not flag:
  print(0)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = 998244353
INF = int(1e15)


def calc(N):
    return sum(int(x) for x in str(N))


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    D = Scanner.map_int()
    if D[0] != 0:
        print(0)
        return
    if D.count(0) != 1:
        print(0)
        return
    C = Counter(D[1:])
    ans = 1
    for i in range(2, len(C) + 1):
        ans *= C[i-1] ** C[i]
    print(ans)
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1 if d[0]<1 else 0
d.sort()
cnt=[0]*(d[-1]+1)
for i in range(n):
  cnt[d[i]]+=1
mod=998244353
for i in d[1:]:
  ans*=cnt[i-1]
  ans%=mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
cnt=[0]*(d[-1]+1)
for i in range(n):
  cnt[d[i]]+=1
ans=1
mod=998244353
for i in range(d[-1]):
  ans*=cnt[i]**cnt[i+1]
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
d.sort()
cnt=[0]*(d[-1]+1)
for i in range(n):
  cnt[d[i]]+=1
ans=1
mod=998244353
for i in range(d[-1]):
  ans*=cnt[i]**cnt[i+1]
print(ans)

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

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

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    if D[0]!=0:
        print(0)
        return
    d = Counter(D)
    loop = max(d.keys())
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

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

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353*min(l))

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    ans = (N-1)//2
    print(ans)
    return

def examB():
    N = I()
    D = LI()
    d = Counter(D)
    loop = max(d.keys())
#    print(d,loop)
    ans = 1; cur = 1
    for i in range(loop+1):
        if d[i]==0:
            print(0)
            return
        for _ in range(d[i]):
            ans *= cur
            ans %= mod2
        cur = d[i]
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LFI(): return list(map(float,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

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

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

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

ans = 1
for i in range(len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Submission status: Wrong Answer

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

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

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

ans = 1
for i in range(2, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
mod = 998244353

def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod

N = int(input())
D = list(map(int, input().split()))
counter = [0] * (10 ** 5)
for d in D:
    counter[d] += 1

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

ans = 1
for i in range(1, N):
    ans *= (mod_pow(counter[i-1], counter[i]) % mod)
print(ans % mod)

Submission status: Wrong Answer

Solution code:
mod = 998244353

def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        half_p = p // 2
        half = mod_pow(a, half_p)
        return half * half % mod
    else:
        return a * mod_pow(a, p - 1) % mod

N = int(input())
D = list(map(int, input().split()))
counter = [0] * (10 ** 5)
for d in D:
    counter[d] += 1

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

ans = 1
for i in range(1, N):
    ans *= mod_pow(counter[i-1], counter[i])
print(ans % mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
counter = [0] * (10 ** 5)
for d in D:
    counter[d] += 1

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

ans = 1
for i in range(1, N):
    ans *= counter[i-1] ** counter[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = lambda: sys.stdin.readline().rstrip()

def counting_tree(N, D):
    tot = 1
    cnt = [0]*N
    # cnt = collections.Counter(D)
    for i in D:
        cnt[i]+=1
        print(cnt)

    for i in D[1:]:
        tot = tot * cnt[i-1]%998244353
        print(tot)

    return tot if D[0]==0 else 0

def main():
    
    N0 = int(read())
    D0 = tuple(map(int, read().split()))

    res = counting_tree(N0, D0)

    print(res)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict


# 累乗
def power(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


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

cnt = defaultdict(int)
for d in D:
    cnt[d] += 1

if cnt.get(0) != 1:
    print(0)
    exit(0)
ans = 1
for i in range(1, max(D) + 1):
    if cnt.get(i) is None:
        print(0)
        exit(0)
    num = pow(cnt[i - 1], cnt[i], MOD)
    ans = ans * num % MOD
print(ans)