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:
p=998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
D = list(map(int,input().split()))
D.insert(0,0)
C = {i:0 for i in range(N)}
for i in range(1,N+1):
    C[D[i]] += 1
if C[0]!=1:
    cnt = 0
else:
    C = sorted(list(C.items()),key=lambda x:x[0])
    ind = 0
    for i in range(N):
        if C[i]==0:
            ind = i
            break
    flag = 0
    if ind>0:
        for i in range(ind+1,N):
            if C[i]>0:
                flag = 1
                break
    if flag==1:
        cnt = 0
    else:
        cnt = 1
        for i in range(1,N):
            if C[i][1]==0:break
            c0 = C[i-1][1]
            c1 = C[i][1]
            cnt = (cnt*(pow(c0,c1)))%p
print(cnt)

Submission status: Wrong Answer

Solution code:
p=998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
D = list(map(int,input().split()))
D.insert(0,0)
C = {i:0 for i in range(N)}
for i in range(1,N+1):
    C[D[i]] += 1
if C[0]!=1:
    cnt = 0
else:
    C = sorted(list(C.items()),key=lambda x:x[0])
    ind = 0
    for i in range(N):
        if C[i]==0:
            ind = i
            break
    flag = 0
    if ind>0:
        for i in range(ind+1,N):
            if C[i]>0:
                flag = 1
                break
    if flag==1:
        print(0)
    else:
        cnt = 1
        for i in range(1,N):
            if C[i][1]==0:break
            c0 = C[i-1][1]
            c1 = C[i][1]
            cnt = (cnt*(pow(c0,c1)))%p
print(cnt)

Submission status: Wrong Answer

Solution code:
p=998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
D = list(map(int,input().split()))
D.insert(0,0)
C = {i:0 for i in range(N)}
for i in range(1,N+1):
    C[D[i]] += 1
if C[0]!=1:
    cnt = 0
else:
    C = sorted(list(C.items()),key=lambda x:x[0])
    cnt = 1
    for i in range(1,N):
        if C[i][1]==0:break
        c0 = C[i-1][1]
        c1 = C[i][1]
        cnt = (cnt*(pow(c0,c1)))%p
print(cnt)

Submission status: Wrong Answer

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

MOD = 998244353
ans = 0
d_comb = [0]*n

if dl[0] == 0:
    ans = 1
    d_comb[0] = 1
else:
    print(0)
    exit()

if n == 1:
    print(1)
    exit()
elif dl[1] == 0:
    print(0)
    exit()

for d in dl[1:]:
    ans *= d_comb[d-1]
    d_comb[d] += 1
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ds = list(mapint())
mod = 998244353
from collections import Counter

c = Counter(Ds)
if Ds[0]!=0:
    print(0)
elif Ds[0]>1:
    print(0)
else:
    ans = 1
    for i in range(1, N):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ds = list(mapint())
mod = 998244353
from collections import Counter

c = Counter(Ds)
if Ds[0]!=0:
    print(0)
elif Ds[0]>1:
    print(0)
else:
    ans = 1
    for i in range(1, N+1):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
# from pprint import pprint
import math

# import collections

n = int(input())


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


def f(a, b):
    return max(math.ceil(math.log10(a)), math.ceil(math.log10(b)))


a = 1
ans = 11
while a <= math.sqrt(n):
    if n % a == 0:
        b = n // a
        if n % a == 0 and f(a, b) <= ans:
            ans = f(a, b)
    a += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ds = list(mapint())
Ds.sort()
mod = 998244353

from collections import Counter
c = Counter(Ds)
dmax = Ds[-1]

if c[0]>1:
    print(0)
else:
    ans = 1
    for i in range(1, dmax+1):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Ds = list(mapint())
Ds.sort()
mod = 998244353

from collections import Counter
c = Counter(Ds)
dmax = Ds[-1]
if len(set(Ds))!=dmax+1:
    print(0)
elif c[0]>1:
    print(0)
else:
    ans = 1
    for i in range(1, dmax+1):
        ans *= pow(c[i-1], c[i], mod)
        ans %= mod
    print(ans)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)
M = max(set(D))

flag = 1 if dic[0] != 1 else 0
ans = 1
for d in range(1, M+1):
    ans *= pow(dic[d-1], dic[d], MOD)
    ans %= MOD

if flag:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)
S = sorted(set(D))

i = 0
flag = 0
ans = 1
for s in S:
    if s != i:
        flag = 1
        break
    i += 1
    if s == 0:
        continue
    ans *= pow(dic[s-1], dic[s], MOD)
    ans %= MOD

if flag:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

ans = 0
cnt = 0
if D[0] == 0:
  D = Counter(D)
  cnt = 1
  ans = 1
  for i in range(1, max(D)+1):
    if D[i] == 0:
      ans = 0
      break
    else:
      ans *= cnt ** D[i]
      cnt = D[i]
ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = 0
cnt = 0
if D[0] == 1:
  cnt = 1
  ans = 1
  for i in range(1, max(D)+1):
    if D[i] == 0:
      ans = 0
    else:
      ans *= cnt ** D[i]
      cnt = D[i]
ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

rank = []
C = Counter(D)
numberList = tuple(sorted(C))
MOD = 998244353
if numberList[-1] != len(numberList)-1:
    print(0)
elif C[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(len(numberList)):
        if i > 0:
            ans *= pow(C[i-1], C[i], MOD)
            ans %= MOD
    print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

rank = []
C = Counter(D)
numberList = tuple(sorted(C))
MOD = 998244353
if numberList != tuple(range(len(numberList))):
    print(0)
elif C[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(len(numberList)):
        if i > 0:
            ans *= pow(C[i-1], C[i], MOD)
            ans %= MOD
    print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

rank = []
C = Counter(D)
numberList = tuple(sorted(C))
MOD = 998244353
if numberList != tuple(range(numberList[-1]+1)):
    print(0)
elif C[0] > 1:
    print(0)
else:
    ans = 1
    for i in range(len(numberList)):
        if i > 0:
            ans *= pow(C[i-1], C[i], MOD)
            ans %= MOD
    print(ans % MOD)

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()
for i in range(1,n):
    if d[i] - d[i-1] > 1:
        print(0)
        exit()
    if d[i] == 0:
        print(0)
        exit()
count = 1
tmp = 1
ans = 1
for i in range(2,n):
    if d[i] != d[i-1]:
        ans *= pow(tmp,count,MOD)
        #print(tmp,count)
        tmp = count
        count = 1
    else:
        count+=1
ans *= pow(tmp,count,MOD)
#print(tmp,count)
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()
for i in range(1,n):
    if d[i] - d[i-1] > 1:
        print(0)
        exit()
    if d[i] == 0:
        print(0)
        exit()
count = 1
tmp = 1
ans = 1
for i in range(1,n):
    if d[i] != d[i-1]:
        ans *= pow(tmp,count,MOD)
        tmp = count
        count = 1
    else:
        count+=1
ans *= pow(tmp,count,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()
for i in range(1,n):
    if d[i] - d[i-1] > 1:
        print(0)
        exit()
count = 1
tmp = 1
ans = 1
for i in range(1,n):
    if d[i] != d[i-1]:
        ans *= pow(tmp,count,MOD)
        tmp = count
        count = 1
    else:
        count+=1
ans *= pow(tmp,count,MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if a[0]!=0:
  print(0)
  quit()
#a.sort()
l=max(a)+1
dp1 = [0]*l
dp2 = [0]*l
ans=0
for i in a:
  dp1[i]+=1
#print(dp1)  

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

dp2[0]=1
#print(dp2)
for i in range(1, l):
  dp2[i]=dp2[i-1]*(dp1[i-1]**dp1[i])

#print(dp2)
print(dp2[l-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
#a.sort()
l=max(a)+1
dp1 = [0]*l
dp2 = [0]*l
ans=0
for i in a:
  dp1[i]+=1
#print(dp1)  

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

dp2[0]=1
#print(dp2)
for i in range(1, l):
  dp2[i]=dp2[i-1]*(dp1[i-1]**dp1[i])

#print(dp2)
print(dp2[l-1])

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    N = int(sysread())
    D = list(map(int, sysread().split()))
    mod = 998244353
    dict = defaultdict(lambda:[])
    max_depth = 0
    for node, d in enumerate(D, 1):
        dict[d].append(node)
        max_depth = max(max_depth, d)
    if dict[0] != [1]:
        print(0)
        return None

    ans = 1
    for i in range(1, max_depth+1):
        pre = len(dict[i-1])
        current = len(dict[i])
        val =pow(pre, current, mod)
        ans *= val
    print(ans)
    return None

    #print(factorials)
if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import product, accumulate, combinations, product
import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque

def run():
    N = int(sysread())
    D = list(map(int, sysread().split()))
    mod = 998244353
    dict = defaultdict(lambda:[])
    max_depth = 0
    for point, d in enumerate(D, 1):
        dict[d].append(point)
        max_depth = max(max_depth, d)
    if dict[0] != [1]:
        print(0)
        return None

    ans = 1
    for i in range(1, max_depth+1):
        try:
            pre = len(dict[i-1])
            current = len(dict[i])
        except:
            print(0)
            return None
        val =pow(pre, current, mod)
        ans *= val
    print(ans)
    return None

    #print(factorials)
if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    D = LI()
    mod = 998244353

    C = [0] * (N+1)
    for d in D:
        C[d] += 1
    # print(C)

    # 木が存在するかを判定
    ans = 1
    p = C[0]
    if not(D[0] == 0 and p == 1):
        print(0)
        return
    for i in range(1, N):
        ci = C[i]
        if ci <= p * 2:
            p = ci
            ans = ans * pow(C[i], C[i+1], mod)
        else:
            print(0)
            return
    print(ans % mod)


    

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()
    D = LI()
    mod = 998244353

    C = [0] * (N+1)
    for d in D:
        C[d] += 1
    # print(C)

    # 木が存在するかを判定
    ans = 1
    p = C[0]
    if p != 1:
        print(0)
        return
    for i in range(1, N):
        ci = C[i]
        if ci <= p * 2:
            p = ci
            ans = ans * pow(C[i], C[i+1], mod)
        else:
            print(0)
            return
    print(ans % mod)


    

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
D = l()
if D.count(0) != 1:
    print(0)
    exit()
if max(D) == 1:
    print(1)
    exit()
dist = [0]*N
for i in range(N):
    dist[D[i]] += 1
ans = 1
for i in range(2,max(D)+1):
    ans *= dist[i-1]**dist[i]
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

mod = 998244353
c = Counter(D)
m = max(c.keys())

if D[0] == 0 and c[0] == 1:
    ans = 1
    for i in D[1:]:
        ans *= c[i-1]
        ans %= mod
else:
    print(0)

Submission status: Wrong Answer

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？
# ケース12と13、完全にバグとしか思えないのですが?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

# もしかして：頂点1は必ず0？

n = int(input())
a = list(map(int, input().split()))
if a[0] != 0:
    print(0)
    exit()
a = sorted(a)
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1
if 0 not in d:
    print(0)
    exit()
MOD = 998244353

ans = 1
for i in range(1, a[-1] + 1):
    if i not in d:
        ans = 0
        break
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？
# ケース12と13、完全にバグとしか思えないのですが?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

# もしかして：頂点1は必ず0？

n = int(input())
a = list(map(int, input().split()))
if a[0] != 0:
    print(0)
    exit()
a = sorted(a)
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

MOD = 998244353

ans = 1
for i in range(1, a[-1] + 1):
    if i not in d:
        ans = 0
        break
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Wrong Answer

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

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

MOD = 998244353

def main():
    N = II()
    D = LII()

    if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    c = Counter(D)
    res = 1

    if c[0] > 1:
       print(0)
       return
    
    mx = max(c.keys())
    for i in range(1, mx+1):
        if i not in c:
            print(0)
            return
        
        res *= c[i-1] ** c[i] % MOD

    print(res)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    D = LII()

    if D[0] != 0 or D.count(0) > 1:
       print(0)
       return 
    
    mx = max(D)
    cnt = 1
    for i in range(1, mx+1):
        pre = D.count(i)
        post = D.count(i+1)
        cnt *= pre ** post
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    D = LII()

    c = Counter(D)
    if D[0] != 0 or c[0] > 1:
        print(0)
        return 

    c = sorted(c.items(), key=lambda c: c[0])

    cnt = 1
    pvalue = 1
    for key, value in c:
        if key == 0:
            continue
        cnt *= pvalue ** value 
        pvalue = value

    print(cnt) 

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？
# ケース12と13、完全にバグとしか思えないのですが?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
for i in range(2, a[-1] + 1):
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
# ？？？？？？？？？？？？？？？？？？？？？？？？？？

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
# for i in range(2, a[-1] + 1):  なんでこれじゃだめなの？
for i in range(1, a[-1] + 1):
    ans *= pow(d[i - 1], d[i], MOD)
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
# 並びは関係なくて、「自分より1小さいところ」ならどこでもいい
# なので自分より1小さいところが無かったらそもそも構築できない
# あと0は1つだけだし1は数えない（0は1つだけなので）
# なんかしらんけどいくつかのケースでWAになった
# ひょっとして注記は各ノードは区別しないって意味か？？？？？？？？？？？？？？？日本語でおｋ
# -> いやありえない サンプル3が凡例
# もしかして: powがクソ？

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
for i in range(2, a[-1] + 1):
    ans *= pow(d[i - 1], d[i], MOD)
# print(ans)
# powがクソかもしれないのでMODする
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
# 並びは関係なくて、「自分より1小さいところ」ならどこでもいい
# なので自分より1小さいところが無かったらそもそも構築できない
# あと0は1つだけだし1は数えない（0は1つだけなので）
# なんかしらんけどいくつかのケースでWAになった
# ひょっとして注記は各ノードは区別しないって意味か？？？？？？？？？？？？？？？日本語でおｋ
# -> いやありえない サンプル3が凡例
# もしかして: powがクソ？

n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
for i in range(1, a[-1]):
    ans *= pow(d[i - 1], d[i], MOD)
# print(ans)
# powがクソかもしれないのでMODする
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
# 並びは関係なくて、「自分より1小さいところ」ならどこでもいい
# なので自分より1小さいところが無かったらそもそも構築できない
# あと0は1つだけだし1は数えない（0は1つだけなので）
n = int(input())
# たしかpythonの辞書は順番も守ってくれた気がするのでソートしとく
a = sorted(list(map(int, input().split())))
d = {}
for av in a:
    if av not in d:
        d[av] = 1
    else:
        d[av] += 1

if a[0] != 0 or d[0] != 1 or len(set(d.keys())) != a[-1] + 1:
    print(0)
    exit()
MOD = 998244353
ans = 1
for i in range(2, a[-1] + 1):
    ans *= pow(d[i - 1], d[i], MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, *d = map(int, open(0).read().split())
MOD = 998244353
c = Counter(d)
if d[0] != 0 or c[0] != 1:
    ans = 0
else:
    ans = 1
    for i in range(1, max(d)+1):
        ans *= (c[i-1] ** c[i]) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, *d = map(int, open(0).read().split())
MOD = 998244353
if d[0] != 0:
    ans = 0
else:
    ans = 1
    c = Counter(d)
    for i in range(1, max(d)+1):
        ans *= (c[i-1] ** c[i]) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n, *d = map(int, open(0).read().split())
MOD = 998244353
if d[0] != 0:
    ans = 0
else:
    ans = 1
    c = Counter(d[1:])
    for item in c.items():
        ans *= (item[0] ** item[1]) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n, *d = map(int, open(0).read().split())
if d[0] != 0:
    ans = 0
else:
    ans = 1
    for D in d[1:]:
            ans *= D
            ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n, *d = map(int, open(0).read().split())
if d[0] != 0:
    ans = 0
else:
    ans = 1
    for D in d[1:]:
        if D != 0:
            ans *= D
            ans = ans % 998244353
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()))
    MAX_L = max(D) + 1
    cnt = [0] * MAX_L

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

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

    res = 1
    for i in range(1, MAX_L):
        if cnt[i] == 0:
            print(0)
            break
        res *= pow(cnt[i - 1], cnt[i], mod)
        res %= mod
    else:
        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()))

    cnt = [0] * n
    for d in D:
        cnt[d] += 1

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

    res = 1
    for i in range(1, n):
        res *= pow(cnt[i - 1], cnt[i], mod)
        res %= 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()))

    cnt = [0] * n
    for d in D:
        cnt[d] += 1

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

    res = 1
    for i in range(1, n):
        res *= pow(cnt[i - 1], cnt[i], mod)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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

MAX = max(D)
count = Counter(D)

ans = 1
for i in range(MAX):
    if count[i] == 0:
        print(0)
        sys.exit()
    ans *= pow(count[i], count[i+1], mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

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

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

MAX = max(D)
count = Counter(D)

ans = 1
for i in range(MAX):
    ans *= pow(count[i], count[i+1], mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = tuple(map(int, input().split()))
maxd = max(D)
mod = 998244353
cd = [0] * (maxd+1)
for d in D:
    cd[d] += 1

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

ans = 1
for i in range(1, maxd+1):
    nodes = cd[i]
    if nodes == 0:
        print(0)
        break
    ans *= pow(pre_nodes, nodes, mod)
    ans %= mod
    pre_nodes = nodes
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = tuple(map(int, input().split()))
maxd = max(D)
mod = 998244353
cd = [0] * (maxd+1)
for d in D:
    cd[d] += 1

if 0 in cd or cd[0] > 1:
    print(0)
else:
    pre_nodes = 1
    ans = 1
    for i in range(1, maxd+1):
        nodes = cd[i]
        ans *= pow(pre_nodes, nodes, mod)
        ans %= mod
        pre_nodes = nodes
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = tuple(map(int, input().split()))
maxd = max(D)
mod = 998244353
cd = [0] * (maxd+1)
for d in D:
    cd[d] += 1

if 0 in cd:
    print(0)
else:
    pre_nodes = 1
    ans = 1
    for i in range(1, maxd+1):
        nodes = cd[i]
        ans *= pow(pre_nodes, nodes, mod)
        ans %= mod
        pre_nodes = nodes
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
C = collections.Counter(D)
for i in range(max(D)+1):
    if C[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(2,max(D)+1):
    ans = (ans * C[i-1]**C[i])%998244353

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
C = collections.Counter(D)
for i in range(max(D)+1):
    if C[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(2,max(D)+1):
    ans = (ans * C[i-1]**C[i])%998244353

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

ans = 1
p = 0.5
for i in range(n):
    c = d.count(i)
    if c > p*2:
        print(0)
        exit()
    else:
        if i > 0:
            ans *= p**c % 998244353
        p = c

print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

ans = 1
p = 0.5
for i in range(n):
    c = d.count(i)
    if c > p*2:
        print(0)
        exit()
    else:
        if i > 0:
            ans *= p**c
        p = c

print(ans)