Problem:


Score : 300 points

Problem Statement

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

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

Notes

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

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

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

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

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

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

import collections
c = collections.Counter(li)

#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])

tmp = c.items()
cnt = list(tmp)
cnt.sort()
#print(cnt)
#[(0, 1), (1, 2), (2, 3), (3, 1)]
ans = 1
for i,c in enumerate(cnt):
    if i == 0:
        if c[1]>=2:
            print(0)
            exit()
        continue
    if c[0]!= i:
        print(0)
        exit()
    ans *= cnt[i-1][1]**c[1]
print(ans)

Submission status: Wrong Answer

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

import collections
c = collections.Counter(li)

#print(c)
# Counter({'a': 4, 'c': 2, 'b': 1})
#print(c.items())
# dict_items([('a', 4), ('b', 1), ('c', 2)])

tmp = c.items()
cnt = list(tmp)
cnt.sort()
#print(cnt)
#[(0, 1), (1, 2), (2, 3), (3, 1)]
ans = 1
for i,c in enumerate(cnt):
    if i == 0:
        if c[1]>=2:
            print(0)
            exit()
    if c[0]>=2:
        if cnt[i-1][0]!= c[0]-1:
            print(0)
            #print('aaaaaa')
            exit()
        #print(cnt[i-1][1]**c[1])
        ans *= cnt[i-1][1]**c[1]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
d = defaultdict(int)
for i in D:
    d[i] += 1
ans = 1
if d[0] != 1:
    print(0)
else:
        
    for i in range(1,N):
        ans = ans*pow(d[i-1],d[i],MOD)
    print(ans%MOD)
    print(pow(0,0,MOD))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
d = defaultdict(int)
for i in D:
    d[i] += 1
ans = 1
for i in range(1,N):
    ans = ans*pow(d[i-1],d[i],MOD)
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
d = defaultdict(int)
for i in D:
    d[i] += 1
ans = 1
for i in range(1,N):
    ans = ans*pow(d[i-1],d[i],MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

mod = 998244353

cnt = defaultdict(int)
for i in range(n):
    cnt[d[i]] += 1

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

ans = 1
for i in range(1, max(d)+1):
    ans *= pow(cnt[i-1], cnt[i], mod)

print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

mod = 998244353
 
cnt = defaultdict(int)
for i in range(n):
    cnt[d[i]] += 1

ans = 1
for i in range(1, max(d)+1):
    ans *= (cnt[i-1]**cnt[i]) % mod

print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

mod = 998244353
 
cnt = defaultdict(int)
for i in range(n):
    cnt[d[i]] += 1

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

print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

mod = 998244353
 
cnt = defaultdict(int)
for i in range(n):
    cnt[d[i]] += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

mod = 998244353
 
cnt = defaultdict(int)
for i in range(n):
    cnt[d[i]] += 1

ans = 1
max_value = max(d)
for i in range(1, max_value+1):
    ans *= pow(cnt[i-1], cnt[i], mod)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
D = list(map(int, sys.stdin.readline().rsplit()))
C = Counter(D)
mod = 998244353

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

res = 1
for i in range(1, max(D) + 1):
    if i not in C:
        print(0)
        exit()
    res *= (C[i - 1] ** C[i]) % mod

print(res)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
D = list(map(int, sys.stdin.readline().rsplit()))
C = Counter(D)
mod = 998244353

if D[0] != 0 or C[0] > 1:
    print(0)
    exit()

res = 1
for i in range(1, max(D) + 1):
    if i not in C:
        print(0)
        exit()
    res *= (C[i - 1] ** C[i]) % mod

print(res)

Submission status: Wrong Answer

Solution code:
import sys

# import re
# import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
MOD2 = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()

    c = collections.Counter(d)
    lim = max(c)

    flg = False
    if d[0] != 0:
        flg = True

    if c[0] != 0:
        flg = True

    for i in range(lim + 1):
        if i not in c.keys():
            flg = True
            break

    if flg:
        print(0)
        exit(0)

    ans = 1
    for i in range(2, lim + 1):
        ans *= pow(c[i - 1], c[i], MOD2)
        ans %= MOD2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
# import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
MOD2 = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()

    c = collections.Counter(d)
    lim = max(c)

    flg = False
    if d[0] != 1:
        flg = True

    for i in range(lim + 1):
        if i not in c.keys():
            flg = True
            break

    if flg:
        print(0)
        exit(0)

    ans = 1
    for i in range(2, lim + 1):
        ans *= pow(c[i - 1], c[i], MOD2)
        ans %= MOD2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

# import re
# import math
import collections
# import decimal
# import bisect
# import itertools
# import fractions
# import functools
import copy
# import heapq
# import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
MOD2 = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    d = na()

    c = collections.Counter(d)
    lim = max(c)

    flg = False
    if d[0] != 0:
        flg = True

    for i in range(lim + 1):
        if i not in c.keys():
            flg = True
            break

    if flg:
        print(0)
        exit(0)

    ans = 1
    for i in range(2, lim + 1):
        ans *= pow(c[i - 1], c[i], MOD2)
        ans %= MOD2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
dmax = max(d)
cnt = [0] * n
for i, dd in enumerate(d):
    cnt[dd] += 1

if d[0] != 0:
    print(0)
    exit()
ans = 1
before = cnt[0]
for i in range(1,dmax+1):
    ans *= pow(before, cnt[i],MOD)
    before = cnt[i]
ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
dmax = max(d)
cnt = [0] * n
for i, dd in enumerate(d):
    cnt[dd] += 1

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
#MOD = 10 ** 9 + 7
MOD = 998244353
def main():
    N = int(readline())
    D = list(map(int, readline().split()))
    if D[0]!=0:
        print(0)
        exit()
    node = [0]*(max(D)+1)
    for i in range(N):
        node[D[i]] += 1
    if node[0]>1:
        print(0)
        exit()
    ans = 0
    for i in range(len(node)-1):
        ans *= node[i]**node[i+1]
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
#MOD = 10 ** 9 + 7
MOD = 998244353
def main():
    N = int(readline())
    D = list(map(int, readline().split()))
    count = Counter(D)
    count = sorted(count.items())
    last = count[-1][0]
    ans = 1
    for i in range(last+1):
        if count[i][0] != i:
            print(0)
            sys.exit()
        if i == 0:
            if count[i][1] != 1:
                print(0)
                sys.exit()
            else:
                continue
        else:
            ans *= (count[i-1][1]**count[i][1]) % MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0]*(n+1)
for i in a:
  c[i] += 1
ans = 1
for i in range(n+1):
    if c[-1] == 0:
        c.pop()
    else:
        break

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0]*(n+1)
for i in a:
  c[i] += 1
ans = 1
for i in c[1:]:
  ans *= i
  ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
c = [0]*(n+1)
for i in a:
  c[i] += 1
ans = 1
for i in c[1:]:
  ans *= i
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(d)

mod=998244353
ans=1
key=set(c.keys())
if c[0]==1 and set(range(len(key)+1)) == key:
    for i in range(len(key)):
        ans=ans*c[i]**c[i+1] %mod
else:
    ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = list(map(int,input().split()))
c = dict(Counter(d))
c = sorted(c.items(), key=lambda x:x[0])
mod=998244353
if d[0]==1 or c[0][1]>1:
    print(0)
else:
    D = 1
    for i in range(1,len(c)):
        D*=c[i-1][1]**c[i][1]
    print(D%mod)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(d)

mod=998244353
ans=1
key=set(c.keys())
if c[0]==1 and set(range(len(key))) == key:
    for i in range(len(key)):
        ans=ans*c[i]**c[i+1] %mod
else:
    ans=0
print(ans)

Submission status: Wrong Answer

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

from collections import Counter
c=Counter(d)

mod=998244353
ans=1
key=set(c.keys())
if c[0]==1 and set(range(len(key))) == key:
    for i in range(len(key)-1):
        ans=ans*c[i]**c[i+1] %mod
else:
    ans=0
print(ans)

Submission status: Wrong Answer

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

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

D.sort()
if D[1] == 0:
    print(0)
    exit()

# 距離の個数を管理
A = []
A.append(1)
cnt = 1
current_number = D[1]
for i in range(2,N):
    if D[i] != current_number:
        current_number = D[i]
        A.append(cnt)
        cnt = 1
        if i == N-1:
            A.append(cnt)
    else:
        cnt += 1
        if i == N-1:
            A.append(cnt)

ans = 1
for i in range(len(A)-1):
    ans *= A[i] ** A[i+1]
    ans %= MOD

print(ans)

Submission status: Wrong Answer

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

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

D.sort()
if D[1] == 0:
    print(0)
    exit()

# 距離の個数を管理
A = []
A.append(1)
cnt = 1
current_number = D[1]
for i in range(2,N):
    if D[i] != current_number:
        current_number = D[i]
        A.append(cnt)
        cnt = 1
        if i == N-1:
            A.append(cnt)
    else:
        cnt += 1
        if i == N-1:
            A.append(cnt)

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

print(ans)

Submission status: Wrong Answer

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

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

D.sort()
if D[1] == 0:
    print(0)
    exit()

# 距離の個数を管理
A = []
A.append(1)
cnt = 1
current_number = D[1]
for i in range(2,N):
    if D[i] != current_number:
        current_number = D[i]
        A.append(cnt)
        cnt = 1
        if i == N-1:
            A.append(cnt)
    else:
        cnt += 1
        if i == N-1:
            A.append(cnt)

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

total = 1
count = 0
for i in range(n):
  num = c.get(i, 0)
  if num == 0:
    total = 0
    break
  count += num
  if i == 0 and c[i] != 1:
    total = 0
  if i > 0:
    total = (total * (c[i - 1] ** c[i])) % 998244353
  if count == n:
    break
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

total = 1
prev = -1
for i in sorted(c.keys()):
  if prev + 1 == i:
    if i == 0 and c[i] != 1:
      total = 0
    if i > 0:
      total = (total * (c[prev] ** c[i])) % 998244353
  else:
    total = 0
  prev = i
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

total = 1
prev = -1
for i in sorted(c.keys()):
  if prev + 1 == i:
    if i > 0:
      total = (total * (c[prev] ** c[i])) % 998244353
  else:
    total = 0
  prev = i
print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

total = 1
prev = c.get(0, 0)
for i in range(len(c)):
  num = c[i]
  if prev == 0:
    total = 0
  else:
    total = (total * (prev ** num)) % 998244353
  prev = num
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
if d[0]!=0:
    print(0)
    exit()
node = [0]*(max(d)+1)
for i in d:
    node[i] += 1
if node[0]>1:
    exit()
ans = 1
for i in range(len(node)-1):
    if node[i]==0:
        print(0)
        break
    ans *= node[i]**node[i+1]
    ans %= 998244353
else:
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 998244353

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from collections import defaultdict

class ModInt:
    def __init__(self, n=0, mod=mod):
        self.mod = mod
        self.n = n % self.mod
    
    def value(self):
        self.n %= self.mod
        return self.n
    
    def __add__(self, rhs):
        if isinstance(rhs, ModInt):
            return self.__class__(self.n + rhs.n, self.mod)
        return self.__class__(self.n + rhs, self.mod)
    
    __radd__ = __add__
    
    def __sub__(self, rhs):
        if isinstance(rhs, ModInt):
            return self.__class__(self.n - rhs.n, self.mod)
        return self.__class__(self.n - rhs, self.mod)
    
    def __rsub__(self, lhs):
        if isinstance(lhs, ModInt):
            return self.__class__(lhs.n - self.n, self.mod)
        return self.__class__(lhs - self.n, self.mod)

    def __mul__(self, rhs):
        if isinstance(rhs, ModInt):
            return self.__class__(self.n * rhs.n, self.mod)
        return self.__class__(self.n * rhs, self.mod)
    
    __rmul__ = __mul__

    def __floordiv__(self, rhs):
        if isinstance(rhs, ModInt):
            return self.__class__(self.n // rhs.n, self.mod)
        return self.__class__(self.n // rhs, self.mod)
    
    def __rfloordiv__(self, lhs):
        if isinstance(lhs, ModInt):
            return self.__class__(lhs.n // self.n, self.mod)
        return self.__class__(lhs // self.n, self.mod)

    def __iadd__(self, rhs):
        if isinstance(rhs, ModInt):
            self.n += rhs.n
        else:
            self.n += rhs
        if self.n >= self.mod:
            self.n -= self.mod
        
        return self
    
    def __isub__(self, rhs):
        rhs_n = rhs.n if isinstance(rhs, ModInt) else rhs
        if self.n < rhs_n:
            self.n += self.mod
        self.n -= rhs_n
        return self
    
    def __imul__(self, rhs):
        rhs_n = rhs.n if isinstance(rhs, ModInt) else rhs
        self.n = self.n * rhs_n % self.mod
        return self
    
    def __ifloordiv__(self, rhs):
        rhs_n = rhs.n if isinstance(rhs, ModInt) else rhs
        exp = self.mod - 2
        while exp:
            if exp % 2:
                self *= rhs_n
            
            rhs_n *= rhs_n
            rhs_n %= self.mod
            exp //= 2
        
        return self
    
    def __pow__(self, exp):
        exp_n = exp.n if isinstance(exp, ModInt) else exp
        if exp_n == 0:
            return self.__class__(1, self.mod)
        if exp_n % 2 == 0:
            t = self.__pow__(exp_n // 2)
            return t * t
        return self * self.__pow__(exp_n - 1)
    
    def __str__(self):
        return str(self.value())


n = ni()
d = na()

dic = defaultdict(int)
max_d = 0
if d[0] >= 1:
    print(0)
    exit()

for i in range(n):
    dic[d[i]] += 1
    max_d = max(max_d, d[i])

ans = ModInt(1)
for i in range(2, max_d + 1):
    ans *= ModInt(dic[i - 1]) ** dic[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            #深さiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1:
        #根が1以外にある
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],m)
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            #歩ささiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1:
        #根が1以外にある
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],m)
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            #歩ささiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1:
        #根が1以外にある
        return 0

    output = 1
    for i in range(n-1):
        output *= pow(MC[i][1],MC[i+1][1],m)
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i-1]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    MC.sort(key = lambda x:x[0])
    print(MC)
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            #歩ささiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1:
        #根が1以外にある
        return 0

    output = 1
    for i in range(n-1):
        output = (output * pow(MC[i][1],MC[i+1][1],m)) % m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    for i in range(len(MC)):
        MC[i] = list(MC[i])
    MC.sort(key = lambda x:x[0])
    
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i:
            #歩ささiと深さi-1又は深さiと深さi+1を繋げない
            return 0
    if MC[0][1] != 1:
        #根が1以外にある
        return 0

    output = 1
    for i in range(n-1):
        output = output * (MC[i][1]**MC[i+1][1] % m)
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    for i in range(len(MC)):
        MC[i] = list(MC[i])
    MC.sort(key = lambda x:x[0])
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def cal(MC,m):
    n = len(MC)
    for i in range(n):
        if MC[i][0] != i or MC[i][1] == 0:
            return 0
    output = 1
    for i in range(n-1):
        output *= (MC[i][1]**MC[i+1][1])
        output %= m
    return output

def main():
    N = int(input())
    D = list(map(int,input().split()))
    M = 998244353
    #頂点1が根じゃないときも連結の仕方を変えずに見方を変えることで
    #頂点1を根にできる.
    #従ってD[i]は頂点iの深さと見なせる
    C = Counter(D)
    MC = C.most_common()
    for i in range(len(MC)):
        MC[i] = list(MC[i])
    MC.sort(key = lambda x:x[0])
    ans = cal(MC,M)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)
tmp = 1
ans = 1
zero_flg = False

for dist in range(N):
    if dist == 0 and c[0] != 1:
        print(0)
        exit()
    elif c[dist] == 0:
        zero_flg = True
    elif c[dist] > 0 and zero_flg:
        print(0)
        exit()
    else:
        ans *= pow(tmp, c[dist], MOD)
        ans %= MOD
        tmp = c[dist]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)
tmp = 1
ans = 1
zero_flg = False

for dist in range(N):
    if dist == 0 and c[0] != 1:
        print(0)
        exit()
    elif c[dist] == 0:
        zero_flg = True
    elif c[dist] > 0 and zero_flg:
        print(0)
        exit()
    else:
        ans *= tmp**c[dist]
        ans %= MOD
        tmp = c[dist]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int, input().split()))
A = [0]*n

for i in range(n):
    A[D[i]] += 1

#print(A)

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

ans = 1
mod = 998244353
for i in range(1, n):
    ans *= A[i-1]**A[i]
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
MOD = 998244353
def main():
    N = int(input())
    D = [int(_) for _ in input().split()]
    s = sorted(list(set(D)))
    if D[0] != 0 or len(s) != s[-1] + 1:
        print(0)
        return
    D = collections.Counter(D)
    output = 1
    for i in sorted(D.keys()):
        if i in (0, 1): continue
        output *= pow(D[i-1], D[i], MOD)
        output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
MOD = 998244353
def main():
    N = int(input())
    D = [int(_) for _ in input().split()]
    s = sorted(list(set(D)))
    if len(s) != s[-1] + 1:
        print(0)
        return
    D = collections.Counter(D)
    output = 1
    for i in sorted(D.keys()):
        if i in (0, 1): continue
        output *= pow(D[i-1], D[i], MOD)
        output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
MOD = 998244353
def main():
    N = int(input())
    D = [int(_) for _ in input().split()]
    if D[0] != 0:
        print(0)
        return
    D = collections.Counter(D)
    output = 1
    for i in sorted(D.keys()):
        if i in (0, 1): continue
        output *= pow(D[i-1], D[i], MOD)
        output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
MOD = 998244353
def main():
    N = int(input())
    D = collections.Counter([int(_) for _ in input().split()])
    output = 1
    if D[0] == 0:
        print(0)
        return
    for i in sorted(D.keys()):
        if i in (0, 1): continue
        output *= pow(D[i-1], D[i], MOD)
        output %= MOD
    print(output)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
mod=998244353
n=int(input())
from collections import Counter as co
l=co(list(map(int,input().split())))
ll=len(l)
for i in range(ll):
    if i not in l:print(0);exit()
if l[0]>=2:print(0);exit()
ans=1
pre=1
for k,v in sorted(l.items()):
    ans*=pow(pre,v,mod)
    ans%=mod
    pre=v
print(ans%mod)

Submission status: Wrong Answer

Solution code:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    import math
    from collections import Counter
    cntr = sorted(Counter(D).items(), key=lambda x: x[0])
    imax = cntr[-1][0]
    if cntr[0] != (0, 1):
        print(0)
        return
    ans = 1
    for i in range(1, imax+1):
        if cntr[i][0] != i:
            ans = 0
            break
        ans = ans * pow(cntr[i-1][1], cntr[i][1], div) % div
    print(ans)

nikkei19q_b()

Submission status: Wrong Answer

Solution code:
def nikkei19q_b():
    _ = int(input())
    D = list(map(int, input().split()))
    div = 998244353

    import math
    from collections import Counter
    cntr = sorted(Counter(D).items(), key=lambda x: x[0])
    imax = cntr[-1][0]
    if cntr[0][0] != 0:
        print(0)
        return
    ans = 1
    for i in range(1, imax+1):
        if cntr[i][0] != i:
            ans = 0
            break
        ans = ans * pow(cntr[i-1][1], cntr[i][1], div) % div
    print(ans)

nikkei19q_b()