Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

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

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

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

cnt = Counter(d)
#print(cnt)
len_cnt = len(cnt)
ans = 0

for i in range(len_cnt):
    if i == 0:
        if cnt[i] == 1:continue
        else:break

    if i == 1:ans = cnt[i]
    else:
        temp = pow(ans, cnt[i], mod)
        if i != len_cnt - 1:temp *= cnt[i]
        ans = temp % 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)
#print(cnt)
len_cnt = len(cnt)
ans = 0

for i in range(len_cnt):
    if i == 0:continue
    if i == 1:ans = cnt[i]
    else:
        temp = pow(ans, cnt[i], mod) * cnt[i]
        ans = temp % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

P = 998244353
N = int(input())
D = [int(x) for x in input().split()]

def solve():
  if D[0] != 0:
    return 0
  total = 1
  max_d = max(D)
  counter = Counter(D)
  if counter[0] != 1:
    return 0
  for i in range(max_d + 1):
    if i not in counter:
      return 0
    if i > 1:
      total *= (counter[i - 1] ** counter[i] % P)
  return total

print(solve())

Submission status: Wrong Answer

Solution code:
from collections import Counter

P = 998244353
N = int(input())
D = [int(x) for x in input().split()]

def solve():
  if D[0] != 0:
    return 0
  total = 1
  max_d = max(D)
  counter = Counter(D)
  for i in range(max_d + 1):
    if i not in counter:
      return 0
    if i > 1:
      total *= (counter[i - 1] ** counter[i] % P)
  return total

print(solve())

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0 or dci[0][1]!=1:
        print(0)
        sys.exit()

    for i,dcii in enumerate(dci):
        if i>1:
            ans*=dci[i-1][1]**dci[i][1]%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0:
        print(0)
        sys.exit()

    for i,dcii in enumerate(dci):
        if i>2:
            ans*=dci[i-1][1]**dci[i][1]%mod
    print(ans%mod)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0:
        print(0)
        sys.exit()

    for i,dcii in enumerate(dci):
        if i>1:
            ans*=dci[i-1][1]**dci[i][1]%mod
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0 or (D[0]==0 and dci[0][1]>1):
        print(0)
        sys.exit()
    for i in range(len(dci)):
        if dci[i][0]!=i:
            print(0)
            break
        if i>=2:
            ans*=dci[i-1][1]**dci[i][1]%mod
    else:
        print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    if D[0]!=0 or (D[0]==0 and dci[0][1]>1):
        print(0)
        sys.exit()
    print(dci)
    for i in range(len(dci)):
        if dci[i][0]!=i:
            print(0)
            break
        if i>=2:
            ans*=dci[i-1][1]**dci[i][1]%mod
    else:
        print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    n=int(input())
    D=[int(_) for _ in input().split()]
    if D[0]!=0:
        print(0)
        sys.exit()
    dc=Counter(D)
    dci=list(dc.items())
    dci.sort()
    mod,ans=998244353,1
    for i,dcii in enumerate(dci):
        if i==1:continue
        ans*=dci[i-1][1]**dcii[1]%mod
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

if nums[0] != 0:
    ans = 0
else:
    ans = 1
    for i in range(1, n):
        ans = ans * nums[i] % mod
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_b
# まず、本当に木を構築するモノではないだろう
from collections import Counter
n = int(input())
nums = [int(i) for i in input().split()]
mod = 998244353

if nums[0] != 0:
    ans = 0
else:
    ans = 1
    for i in range(1, n):
        ans *= nums[i] % 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()
del d[0]
for i in range(n-1):
    if d[i]==0:
        print(0)
        exit()
dcnt=[0]*(n)
for i in range(n-1):
    dcnt[d[i]]+=1
for j in range(n-1,-1,-1):
    if dcnt[j]==0:
        del dcnt[j]
    else:
        break
if len(dcnt)==0:
    print(0)
    exit()
sum=1
for i in range(1,len(dcnt)):
    sum*=pow(dcnt[i-1],dcnt[i])
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    exit()
del d[0]
dcnt=[0]*(n)
for i in range(n-1):
    dcnt[d[i]]+=1
for j in range(n-1,-1,-1):
    if dcnt[j]==0:
        del dcnt[j]
    else:
        break
dcnt[0]=1
sum=1
for i in range(1,len(dcnt)):
    sum*=pow(dcnt[i-1],dcnt[i])
print(sum)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_b
# まず、本当に木を構築するモノではないだろう
n = int(input())
nums = [int(i) for i in input().split()]
mod = 998244353

MAX = max(nums)
s = set(nums)

def check(s, MAX):
    for i in range(MAX):
        if i not in s:
            return False
    return True

if not check(s, MAX):
    ans = 0
else:
    ans = 1
    for i in range(1, n):
        ans *= nums[i] % mod
print(ans % mod)

Submission status: Wrong Answer

Solution code:
import sys
MOD = 998244353
class ModInt:

	def __init__(self, x, inv=None):
		self.x = x.x if isinstance(x, ModInt) else x % MOD
		self.inv = inv

	__str__ = lambda self:str(self.x)
	__repr__ = __str__
	__int__ = lambda self: self.x
	__index__ = __int__

	__add__ = lambda self, other: ModInt(self.x + ModInt(other).x)
	__radd__ = lambda self, other: ModInt(other + self.x)
	__iadd__ = __add__

	__sub__ = lambda self, other: ModInt(self.x - ModInt(other).x)
	__rsub__ = lambda self, other: ModInt(other - self.x)
	__isub__ = __sub__

	__mul__ = lambda self, other: ModInt(self.x * ModInt(other).x)
	__rmul__ = lambda self, other: ModInt(other * self.x)
	__imul__ = __mul__

	__pow__ = lambda self, other: ModInt(pow(self.x, ModInt(other).x, MOD))
	__rpow__ = lambda self, other: ModInt(pow(other, self.x, MOD))
	__pow__ = __pow__

	def __truediv__(self, other):
		if isinstance(other, ModInt) and other.inv != None:
			return ModInt(self.x * other.inv)
		else:
			return ModInt(self.x * pow(ModInt(other).x, MOD - 2, MOD))
	
	def __rtruediv__(self, other):
		if not self.inv:
			return ModInt(other * pow(self.x, MOD - 2, MOD))
		else:
			return ModInt(other * self.inv)

	__itruediv__ = __truediv__

	__floordiv__ = lambda self, other: ModInt(self.x // ModInt(other).x)
	__rfloordiv__ = lambda self, other: ModInt(other // self.x)
	__ifloordiv__ = __floordiv__

	__mod__ = lambda self, other: ModInt(self.x % other)
	__rmod__ = lambda self, other: ModInt(other % self.x)
	__imod__ = __mod__

	__lt__ = lambda self, other: self.x < ModInt(other).x
	__gt__ = lambda self, other: self.x > ModInt(other).x
	__le__ = lambda self, other: self.x <= ModInt(other).x
	__ge__ = lambda self, other: self.x >= ModInt(other).x
	__eq__ = lambda self, other: self.x == ModInt(other).x
	__ne__ = lambda self, other: self.x != ModInt(other).x

class Comb:
	def __init__(self, fact):
		self.fact = fact
	def __call__(self, n, r):
		if n < 0 or r < 0 or n < r:
			return 0
		r = min(r, n-r)
		return self.fact(n) // self.fact(n-r) // self.fact(r)

class Fact:
	def __init__(self, MAX):
		MAX += 1
		self.fact = [0] * MAX
		finv = [0] * MAX
		inv = [0] * MAX
		self.fact[0] = 1
		self.fact[1] = 1
		finv[0] = 1
		finv[1] = 1
		inv[1] = 1
		for i in range(2, MAX):
			self.fact[i] = self.fact[i - 1] * i % MOD
			inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
			finv[i] = finv[i - 1] * inv[i] % MOD
		for i in range(MAX):
			self.fact[i] = ModInt(self.fact[i], inv=finv[i])
	def __call__(self, value):
		return self.fact[value]


def main():
	n = int(sys.stdin.readline())
	d = list(map(int, sys.stdin.readline().split()))
	if d[0] != 0:
		print(0)
		exit()
	d.sort()
	cnt = [0]*n
	for i in range(n):
		cnt[d[i]] += 1
	ans = ModInt(1)
	fact = Fact(10**5)
	comb = Comb(fact)
	for i in range(1, n):
		if cnt[i] == 0:
			continue
		ans *= cnt[i-1]**ModInt(cnt[i])
	print(ans)


main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
for i in range(1, len(cnt)):
    if cnt[i][0] - cnt[i-1][0] != 1:
        print(0)
        exit()
    ans = ans * (cnt[i-1][1]**cnt[i][1]) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
for i in range(1, len(cnt)):
    if cnt[i][0] - cnt[i-1][0] != 1:
        print(0)
        exit()
    ans *= (cnt[i-1][1]**cnt[i][1])
print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
for i in range(1, len(cnt)):
    if cnt[i][0] - cnt[i-1][0] != 1:
        print(0)
        exit()
    ans *= (cnt[i-1][1]**cnt[i][1]) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
for i in range(1, len(cnt)):
    if cnt[i][0] - cnt[i-1][0] != 1:
        print(0)
        exit()
    ans *= (cnt[i-1][1]**cnt[i][1]) % mod
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
for i in range(1, len(cnt)):
    if cnt[i][0] - cnt[i-1][0] != 1:
        print(0)
        exit()
    ans *= (cnt[i-1][1]**cnt[i][1]) % mod
    ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
if cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    ans *= (cnt[i-1][1]**cnt[i][1]) % mod
    ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt or cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    ans *= (cnt[i-1][1]**cnt[i][1]) % mod
    ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt or cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 1
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    ans *= (cnt[i-1][1]**cnt[i][1])
    ans %= mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt or cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 0
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    if pre_k == 1: ans += 1
    ans *= (cnt[i-1][1]**cnt[i][1])
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt or cnt[0] != 1:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 0
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    if pre_k == 1:
        ans += 1
        continue
    ans *= (cnt[i-1][1]**cnt[i][1])
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 0
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    if pre_k == 1:
        ans += 1
        continue
    ans *= (cnt[i-1][1]**cnt[i][1])
print(ans % mod)

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x: x[0])
ans = 0
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    if pre_k == 1:
        ans += 1
        continue
    ans *= (cnt[i-1][1]**cnt[i][1])
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
cnt = Counter(d)
if 0 not in cnt:
    print(0)
    exit()
cnt = sorted(cnt.items(), key=lambda x:x[0])
ans = 0
pre_k = 0
for i in range(1, len(cnt)):
    if cnt[i][0] - pre_k != 1:
        print(0)
        exit()
    pre_k = cnt[i][0]
    if pre_k == 1:
        ans += 1
        continue
    ans *= cnt[i-1][1]**cnt[i][1] % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


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

    tree = [0 for _ in range(max(D) + 1)]
    for i in range(n):
        idx = D[i]
        tree[idx] += 1

    res = 1
    for i in range(len(tree) - 1):
        res *= pow(tree[i], tree[i + 1], mod)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


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

    tree = [0 for _ in range(max(D) + 1)]
    for i in range(n):
        idx = D[i]
        tree[idx] += 1

    res = 1
    for i in range(len(tree) - 1):
        res *= pow(tree[i], tree[i + 1]) % mod

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

N = INT()
D = LIST()

cnt_D = Counter(D)
if cnt_D[0] >= 2:
	print(0)
	exit()

ans = 1

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

Submission status: Wrong Answer

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

N = INT()
D = LIST()

cnt_D = Counter(D)
ans = 1

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

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 998244353
 
    N = II()
    D = LMIIS()
    num_D = [0]*N
    for d in D:
        num_D[d] += 1
    if num_D[0] != 1:
        print(0)
        return
    ans = 1
    prev = 1
    dbg(num_D)
    for i,v in enumerate(num_D):
        if v == 0:
            if N-i != num_D[i:].count(0):
                print(0)
                return
            break
        ans *= pow(prev,v,MOD)
        ans %= MOD
        prev = v
    print(ans)


    

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 998244353
 
    N = II()
    D = LMIIS()
    num_D = [0]*N
    for d in D:
        num_D[d] += 1
    if num_D[0] != 1:
        print(0)
        return
    ans = 1
    prev = 1
    for v in num_D[1:]:
        if v == 0:
            break
        ans *= pow(prev,v,MOD)
        ans %= MOD
        prev = v
    print(ans)


    

    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

#以下が an mod p を求めるソースコードです.
def power_func(a, n, p):
    res = 1 #これは答え
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p #1が立っているかどうかに関わらず次のaの累乗を用意しておく
        n = n >> 1
    return res

bucket = [0] * (max(D) + 1)
for dist in D:
    bucket[dist] += 1
# print(bucket)

if bucket[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(bucket) - 1):
        ans = (ans * power_func(bucket[i], bucket[i + 1], MOD)) % MOD
    print(ans)

Submission status: Wrong Answer

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

#以下が an mod p を求めるソースコードです.
def power_func(a, n, p):
    res = 1 #これは答え
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p #1が立っているかどうかに関わらず次のaの累乗を用意しておく
        n = n >> 1
    return res

bucket = [0] * (max(D) + 1)
for dist in D:
    bucket[dist] += 1
# print(bucket)

if bucket[0] != 1 or 0 in bucket:
    print(0)
else:
    ans = 1
    for i in range(len(bucket) - 1):
        ans = (ans * power_func(bucket[i], bucket[i + 1], MOD)) % MOD
    print(ans)

Submission status: Wrong Answer

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

#以下が an mod p を求めるソースコードです.
def power_func(a, n, p):
    res = 1 #これは答え
    while n > 0:
        if n & 1:
            res = res * a % p
        a = a * a % p #1が立っているかどうかに関わらず次のaの累乗を用意しておく
        n = n >> 1
    return res

bucket = [0] * (max(D) + 1)
for dist in D:
    bucket[dist] += 1
# print(bucket)

if bucket[0] > 1 or 0 in bucket:
    print(0)
else:
    ans = 1
    for i in range(len(bucket) - 1):
        ans = (ans * power_func(bucket[i], bucket[i + 1], MOD)) % MOD
    print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 0:
    print(0)
    exit()
elif dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] > 1:
    print(0)
    exit()
if dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 1:
    print(0)
    exit()
if dist[0]>1:
    print(0)
    exit()

ans = 1
for i in range(max_d):
    if dist[i] == 0 or dist[i+1] ==0:
        print(0)
        exit()
    ans *= (dist[i]**dist[i+1])%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d-1] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] != 1:
    print(0)
    exit()

ans = 1
for i in range(max_d-1):
    if dist[i]==0 or dist[i+1]==0:
        print(0)
        exit()
    ans = (ans*(dist[i]**dist[i+1]))%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d-1] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] == 1:
    print(0)
    exit()

ans = 1
for i in range(max_d-1):
    if dist[i]==0 or dist[i+1]==0:
        print(0)
        exit()
    ans = (ans*(dist[i]**dist[i+1]))%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d-1] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] == 1:
    print(0)
    exit()
elif dist[1] == 0:
    print(dist[0])
    exit()

ans = 1
for i in range(max_d-1):
    ans = (ans*(dist[i]**dist[i+1]))%MOD
print(ans)

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] == 1:
    print(0)
    exit()
elif dist[0] == 0:
    print(0)
    exit()

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

Submission status: Wrong Answer

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

dist = [0] * 10**5
max_d = 0
for d in d_list:
    dist[d] += 1
    max_d = max(max_d, d)

MOD = 998244353
if d_list[0] == 1:
    print(0)
    exit()
elif dist[1] == 0:
    print(dist[0])
    exit()

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

Submission status: Wrong Answer

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # cnt[k] = v ... 深さkのノード数
    cnt = {}
    max_depth = 0
    for d in D:
        max_depth = max(max_depth, d)
        if d not in cnt:
            cnt[d] = 1
        else:
            cnt[d] += 1

    # 頂点1との距離が0になるノードは1つしか存在しない
    if 0 not in cnt:
        print(0)
        exit(0)
    elif cnt[0] > 1:
        print(0)
        exit(0)

    ans = 1
    MOD = 998244353
    for i in range(0, max_depth):
        if (i not in cnt) or (i + 1 not in cnt):
            ans = 0
            break
        for _ in range(cnt[i + 1]):
            ans *= cnt[i]
            ans %= MOD

    print(ans)

Submission status: Wrong Answer

Solution code:
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # cnt[k] = v ... 深さkのノード数
    cnt = {}
    max_depth = 0
    for d in D:
        max_depth = max(max_depth, d)
        if d not in cnt:
            cnt[d] = 1
        else:
            cnt[d] += 1

    # 頂点1との距離が0になるノードは1つしか存在しない
    if 0 not in cnt:
        print(0)
        exit(0)
    elif cnt[0] > 1:
        print(0)
        exit(0)

    ans = 1
    MOD = 998244353
    for i in range(0, max_depth):
        if (i not in cnt) or (i + 1 not in cnt):
            ans = 0
            break
        ans *= cnt[i] ** cnt[i + 1]
        ans %= MOD

    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)
MOD = 998244353


def main():
    N = int(input())
    D = list(map(int, input().split()))
    C = Counter(D)
    if D[0] != 0:
        print(0)
    elif C[0] > 1:
        print(0)
    else:
        ans = 1
        key = list(C.keys())
        key.sort()
        l = len(key)
        for i in range(1, l):
            a = C[key[i - 1]] ** C[key[i]]
            ans *= a
            ans %= MOD
        print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
MOD = 998244353

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

aa = Counter(a)
ma = max(aa)

def po(x,n):
    k = 1
    for i in range(n):
        k = k*x % MOD
    return k

if aa[0] != 1:
    print(0)
    sys.exit()
ans = 1
for i in range(ma):
    c,d = aa[i],aa[i+1]
    if c == 0 or d == 0:
        print(0)
        sys.exit()
    else:
        ans = ans * po(c,d) % MOD
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353

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

aa = Counter(a)
ma = max(aa)

def po(x,n):
    k = 1
    for i in range(n):
        k = k*x % MOD
    return k

ans = 1
for i in range(ma):
    c,d = aa[i],aa[i+1]
    if c == 0 or d == 0:
        ans *= 0
    else:
        ans = ans * po(c,d) %  MOD
        
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353

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

aa = Counter(a)
ma = max(aa)

def po(x,n):
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K = K*x % MOD
        x = x**2 % MOD
        n //= 2

    return K * x % MOD

ans = 1
for i in range(ma):
    c,d = aa[i],aa[i+1]
    if c == 0 or d == 0:
        ans *= 0
    else:
        ans = ans * po(c,d) %  MOD
        
print(ans)

Submission status: Wrong Answer

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

cnt = [0]*n
for i in range(n):
    cnt[a[i]] += 1
for i in range(1,n):
    ans *= cnt[a[i]-1]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

depth = defaultdict(set)
for idx, d in enumerate(D):
    depth[d].add(idx + 1)

# つながらない
for k in range(max(D) + 1):
    if k not in depth:
        print(0)
        exit()

mod = 998244353
ans = 1
d = 1
while d <= max(D):
    ans *= pow(len(depth[d - 1]), len(depth[d]), mod)
    ans %= mod
    d += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

depth = defaultdict(set)
for idx, d in enumerate(D):
    depth[d].add(idx + 1)

# つながらない
for k in range(max(D) + 1):
    if k not in depth:
        print(0)
        exit()

# print(N)
# print(D)
# print(depth)

mod = 998244353

# depth 2から順番に計算
# ans = 1 * len(depth[1])
ans = 1
for d in range(2, max(D) + 1):
    f = pow(len(depth[d - 1]), len(depth[d]), mod)
    # print(d, f, ans)
    ans *= f
    ans %= mod
print(ans)