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())
A = list(map(int, input().split()))

AC = list(Counter(A).items())
AC.sort()
MOD = 998244353
ans = 1
last_v = 1
last_k = -1
for k, v in AC:
  if k == 0:
    if v > 1:
      print(0)
      exit()
    last_k = 0
    continue
  if k != last_k+1:
    print(0)
    exit()
  ans = ans*pow(last_v, v, MOD)%MOD
  last_v = v
  last_k = k
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

AC = list(Counter(A).items())
AC.sort()
MOD = 998244353
ans = 1
last_v = 1
last_k = -1
for k, v in AC:
  if k == 0:
    last_k = 0
    continue
  if k != last_k+1:
    print(0)
    exit()
  ans = ans*pow(last_v, v, MOD)%MOD
  last_v = v
  last_k = k
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

AC = list(Counter(A).items())
AC.sort()
MOD = 998244353
ans = 1
last = 1
for k, v in AC:
  if k == 0:
    continue
  ans = ans*pow(last, v, MOD)%MOD
  last = v
print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
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 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

n = k()
d = l()

d.sort()
count = Counter(d)
if d[0] == 0 and d[1] != 0:
    ans = 1
else:
    ans = 0

for i in range(max(count)):
    ans *= count[i]**count[i+1]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

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

cnt=[0]*(max(D)+1)
MOD=998244353
for i in range(N):
    cnt[D[i]]+=1

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

Submission status: Wrong Answer

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

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1
ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    if s[i] > 1:
      print (0)
      exit()
    continue
  ans *= pow(s[i-1],(s[i]),mod)
  ans %= mod
print (ans%mod)

Submission status: Wrong Answer

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

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1
ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    if s[i] > 1:
      print (0)
      exit()
    continue
  ans *= pow(s[i-1],(s[i]),mod)
  ans %= mod
print (ans)

Submission status: Wrong Answer

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

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1
ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    if s[i] > 1:
      print (0)
      exit()
    continue
  ans *= s[i-1]**(s[i])
  ans %= mod
print (ans)

Submission status: Wrong Answer

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

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1
ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    continue
  ans *= s[i-1]**(s[i])
  ans %= mod
print (ans)

Submission status: Wrong Answer

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

d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]

for i in range(n):
  s[d[i]] += 1

ans = 1
for i in range(len(s)):
  if s[i] == 0:
    print (0)
    exit()
  if i == 0:
    continue
  ans *= i**(s[i])
  ans %= mod
print (ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
import collections
ans=1
dd=collections.Counter(d)
dd=sorted(dd.items())
#print(dd)
if dd[0][1]!=1:
    print("a")
    print(0)
    sys.exit()
for i in range(max(d)+1):
    if i not in d:
        print(0)
        sys.exit()

for i in range(max(d)):#0~n-1
    ans*=dd[i][1]**dd[i+1][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
import collections
ans=1
dd=collections.Counter(d)
dd=sorted(dd.items())
#print(dd)
if dd[0][1]!=1:
    print(0)
    sys.exit()
for i in range(max(d)+1):
    if i not in dd:
        print(0)
        sys.exit()

for i in range(max(d)):#0~n-1
    ans*=dd[i][1]**dd[i+1][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
import collections
ans=1
dd=collections.Counter(d)
dd=sorted(dd.items())
print(dd)
if dd[0][1]!=1:
    print(0)
    sys.exit()
for i in range(max(d)+1):
    if i not in dd:
        print(0)
        sys.exit()

for i in range(max(d)):#0~n-1
    ans*=dd[i][1]**dd[i+1][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
import collections
ans=1
dd=collections.Counter(d)
dd=sorted(dd.items())
if dd[0]!=1:
    print(0)
    sys.exit()
for i in range(max(d)+1):
    if i not in dd:
        print(0)
        sys.exit()

for i in range(max(d)):#0~n-1
    ans*=d[i][1]**d[i+1][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0 or 0 in d[1:]:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for i in range(len(d)):
    if d[i][0]==0:
        continue
    ans*=d[i-1][1]**d[i][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0 or 0 in d[1:]:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for i in range(len(d)):
    if d[i][0]==1 or d[i][0]==0:
        continue
    ans*=d[i-1][1]**d[i][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for i in range(len(d)):
    if d[i][0]==1 or d[i][0]==0:
        continue
    if d[i][1]==0:
        print(0)
        sys.exit()
    ans*=d[i-1][1]**d[i][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

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

#l = list(map(int, input().split()))
#import numpy as np
#arr = np.array([int(i) for i in input().split()])
'''
a,b=[],[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

n=int(input())
d=list(map(int,input().split()))
if d[0]!=0:
    print(0)
    sys.exit()
import collections
ans=1
d=collections.Counter(d)
d=sorted(d.items())
for i in range(len(d)):
    if d[i][0]==1 or d[i][0]==0:
        continue
    if d[i-1][1]==0:
        print(0)
        sys.exit()
    ans*=d[i-1][1]**d[i][1]
    if ans>998244353:
        ans%=998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
mod=998244353
A=list(map(int,input().split()))
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as frac  #frac(a,b)で正確なa/b
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

C=Counter(A)
Q=[C[i] for i in range(max(A)+1)]
#print(Q)
ans=1
for i  in range(len(Q)-1):
    ans*= pow(Q[i],Q[i+1],mod)
    ans%=mod

print(ans)

Submission status: Wrong Answer

Solution code:
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
m=max(D)
if D[0]>0 or c[0]>1 or 0 in c[:m]:print(0);exit()
a=1
for i in range(m):a*=c[i]**c[i+1]
print(a)

Submission status: Wrong Answer

Solution code:
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
m=max(D)
if D[0]>0 or c[0]>1 or 0 in D[1:m+1]:print(0);exit()
a=1
for i in range(max(D)):a*=c[i]**c[i+1]
print(a)

Submission status: Wrong Answer

Solution code:
N,*D=map(int,open(0).read().split())
c=[0]*N
for i in D:c[i]+=1
if D[0]>0 or c[0]>1:print(0);exit()
a=1
for i in range(max(D)):a*=c[i]**c[i+1]
print(a)

Submission status: Wrong Answer

Solution code:
from sys import exit
from collections import Counter
mod = 998244353
n = int(input())
D = list(map(int, input().split()))
m = max(D)
C = Counter(D)
ans = 1
if C.get(0):
    if C[0] != 1:
        print(0)
        exit()
else:
    print(0)
    exit()
for i in range(0, m):
    if C.get(i + 1):
        ans *= (C[i] ** C[i + 1]) % mod
        ans %= mod
    else:
        print(0)
        exit()

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import exit
from collections import Counter
mod = 998244353
n = int(input())
D = list(map(int, input().split()))
m = max(D)
C = Counter(D)
ans = 1
if C.get(0):
    if C[0] != 1:
        print(0)
        exit()
else:
    print(0)
    exit()
for i in range(0, m):
    if C.get(i):
        if C.get(i + 1):
            ans *= (C[i] ** C[i + 1]) % mod
            ans %= mod
        else:
            print(0)
            exit()
    else:
        print(0)
        exit()
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import lru_cache
mod = 998244353
n = int(input())
D = list(map(int, input().split()))
m = max(D)
C = Counter(D)
ans = 1

for i in range(0, m):
    if C.get(i):
        if C.get(i + 1):
            ans *= (C[i] ** C[i + 1]) % mod
            ans %= mod
        else:
            print(0)
            break
    else:
        print(0)
        break
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
t = list(map(int, input().split()))
max_t = max(t)
ans = 1
for m in range(max_t):
  if m not in t:
    ans = 0
if t.count(0) >= 2:
  ans = 0
    
MOD = 998244353
if ans == 1:
  if t[0] != 0:
    ans = 0
  else:
    d = defaultdict(int)
    for t_i in t:
      d[t_i] += 1
    d = sorted(d.items(), key=lambda x:x[0])
    ans = 1
    for k, v in d:
      if k == 0:
        i = 1
        num = 1
        continue
      else:
        ans *= pow(num, v, MOD) % MOD
        num = v
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
t = list(map(int, input().split()))

MOD = 998244353
if t[0] != 0:
  ans = 0
else:
  d = defaultdict(int)
  for t_i in t:
    d[t_i] += 1
  if d[0] >= 2:
    ans = 0
  else:
    d = sorted(d.items(), key=lambda x:x[0])
    ans = 1
    for k, v in d:
      if k == 0:
        i = 1
        num = 1
        continue
      elif k != i:
        ans = 0
        break
      else:
        ans *= pow(num, v, MOD) % MOD
        num = v
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
t = list(map(int, input().split()))

MOD = 998244353
if t[0] != 0:
  ans = 0
else:
  d = defaultdict(int)
  for t_i in t:
    d[t_i] += 1
  if d[0] >= 2:
    ans = 0
  else:
    d = sorted(d.items(), key=lambda x:x[0])
    ans = 1
    for k, v in d:
      if k == 0:
        i = 1
        num = 1
        continue
      elif k != i:
        ans = 0
        break
      else:
        ans *= num**v % 998244353
        num = v
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
t = list(map(int, input().split()))

if t[0] != 0:
  ans = 0
else:
  d = defaultdict(int)
  for t_i in t:
    d[t_i] += 1
  if d[0] >= 2:
    ans = 0
  else:
    d = sorted(d.items(), key=lambda x:x[0])
    ans = 1
    for k, v in d:
      if k == 0:
        i = 1
        num = 1
        continue
      elif k != i:
        ans = 0
        break
      else:
        ans *= num**v
        num = v
        i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
ddic = collections.Counter(d)
nn = 998244353

maxd = max(ddic)

if any(x not in ddic for x in range(maxd)):
    print(0)
elif ddic.get(0) != 1:
    print(0)
else:
    ans = 1
    for i in range(1, len(ddic)):
        ans = (ans * (ddic.get(i, 1) ** ddic.get(i + 1, 1)))  % nn
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
ddic = collections.Counter(d)
nn = 998244353

maxd = max(ddic)

if any(x not in ddic for x in range(maxd)):
    print(0)
else:
    ans = 1
    for i in range(1, len(ddic)):
        ans = (ans * ddic.get(i, 1) ** ddic.get(i + 1, 1))  % nn
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

C = sorted(Counter(D).most_common(), key=lambda x: x[0])

if C[0][1] > 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(C)):
    ans *= C[i - 1][1] ** C[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()))

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

C = sorted(Counter(D).most_common(), key=lambda x: x[0])

if C[0][1] > 1:
    print(0)
    exit()

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

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

C = sorted(Counter(D).most_common(), key=lambda x: x[0])

if C[0][1] > 1:
    print(0)
    exit()

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
L = list(map(int,input().split()))
MOD = 998244353

from collections import Counter
if L[0] != 0:
    print(0)
    exit()

dp = [1]*100010
for i in range(1,100001):
    dp[i] = dp[i-1]*(i+1)%MOD

li = Counter(L)

ans = 1
for k,v in li.items():
    if k != 0:
        ans *=dp[v-1]%MOD
print(ans)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    tmp = [0 for _ in range(10 ** 5)]
    for i in range(N):
        tmp[D[i]] += 1

    ans = 1
    flag = False
    flag2 = False
    for i in range(10 ** 5 - 1):

        if flag2 and tmp[i+1]:
            ans = 0
            break

        if tmp[i+1] == 0:
            flag2 = True

        ans = (ans * (tmp[i] ** tmp[i+1])) % 998244353

    print(ans)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    tmp = [0 for _ in range(10 ** 5)]
    for i in range(N):
        tmp[D[i]] += 1

    ans = 1
    flag = False
    for i in range(10 ** 5 - 1):
        if tmp[i+1] == 0:
            break

        ans = (ans * (tmp[i] ** tmp[i+1])) % 998244353

    print(ans)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    tmp = [0 for _ in range(10 ** 5)]
    for i in range(N):
        tmp[D[i]] += 1

    ans = 1
    flag = False
    for i in range(10 ** 5 - 1):
        if tmp[i+1] == 0:
            break

        ans = ans * (tmp[i] ** tmp[i+1]) 

    print(ans)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    tmp = [0 for _ in range(10 ** 5)]
    for i in range(N):
        tmp[D[i]] += 1

    ans = 1
    flag = False
    for i in range(10 ** 5 - 1):
        if tmp[10 ** 5-i-1] != 0:
            flag = True

        if flag:
            ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]
            ans = ans % 998244353

    print(ans)

Submission status: Wrong Answer

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

if D[0] == 0:
    print(0)
else:
    tmp = [0 for _ in range(10 ** 5)]
    for i in range(N):
        tmp[D[i]] += 1

    ans = 1
    flag = False
    for i in range(10 ** 5 - 1):
        if tmp[10 ** 5-i-1] != 0:
            flag = True

        if flag:
            ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]
            ans = ans % 998244353

    print(ans)

Submission status: Wrong Answer

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
    tmp[D[i]] += 1

ans = 1
flag = False
for i in range(10 ** 5 - 1):
    if tmp[10 ** 5-i-1] != 0:
        flag = True

    if flag:
        ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]
        ans = ans % 998244353

print(ans)

Submission status: Wrong Answer

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
    tmp[D[i]] += 1

ans = 1
flag = False
for i in range(10 ** 5 - 2):
    if tmp[10 ** 5-i-1] != 0:
        flag = True

    if flag:
        ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]
        ans = ans % 998244353

print(ans)

Submission status: Wrong Answer

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
    tmp[D[i]] += 1

ans = 1
flag = False
for i in range(10 ** 5 - 2):
    if tmp[10 ** 5-i-1] != 0:
        flag = True

    if flag:
        ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]

print(ans)

Submission status: Wrong Answer

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

tmp = [0 for _ in range(10 ** 5)]
for i in range(N):
    tmp[D[i]] += 1

ans = 1
flag = False
for i in range(10 ** 5 - 1):
    if tmp[10 ** 5-i-1] != 0:
        flag = True

    if flag:
        ans *= tmp[10 ** 5 - i - 2] ** tmp[10 ** 5 - i - 1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
mod=998244353
if D[0] != 0:
    print(0)
else:
    ans=1
    del D[0]
    if 0 in D:
        print(0)
    else:
        numbers=Counter(D)
        for n in range(2,max(numbers.keys())+1):
            if not n in D:
                ans=0
                break
            ans*=numbers[n-1]**numbers[n]
        print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N=int(input())
*d,=map(int,input().split())
mod = 998244353

if d[0]:
  print(0)
  exit(0)
  
dmax = max(d)
if sorted(set(d)) != list(range(dmax+1)):
  print(0)
  exit(0)

c = Counter(d)

ans =1
for i in range(2,dmax+1):
  ans *= pow(c[i-1],c[i],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()))
if d[0] != 0:
    print(0)
    exit()

C = Counter(d)
C = dict(sorted(C.items()))
print(C)

memo1 = C[1]
memo2 = 1
ans = 1

for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
        print(key)
        if memo2 + 1 != key: #道が途切れている場合はダメ
            print(0)
            exit()
        ans = (ans * memo1 ** C[key]) % mod #modは和について閉じているため先にわる
        memo1 = C[key]
        memo2 = key
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()

C = Counter(D)
C = dict(sorted(C.items()))

memo = C[1]
ans = 1
for i in range(1,n):
    if D[i] == 0:
        print(0)
        exit()

for key in C:
    if key >= 2:
       ans = (ans * (pow(memo,C[key])))%998244353
       memo = C[key]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()

C = Counter(D)
C = dict(sorted(C.items()))

memo = 1
ans = 1
for i in range(1,n):
    if D[i] == 0:
        print(0)
        exit()
        
for key in C:
    ans = (ans * (pow(memo,C[key])))%998244353
    memo = C[key]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0:
    print(0)
    exit()

C = Counter(D)
C = dict(sorted(C.items()))

memo = 1
ans = 1
for key in C:
    ans = (ans * (pow(memo,C[key])))%998244353
    memo = C[key]
print(ans)

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

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


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

Submission status: Wrong Answer

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

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


ans = 1
for i in range(1,n):
    if D[i] == 0:
        print(0)
        exit()
    else:
        ans *= D[i]
print(ans)

Submission status: Wrong Answer

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


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in range(2, max(d)+1):
            ans *= pow(D[i-1], D[i], MOD)
            ans %= MOD
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in range(1, max(d)+1):
            ans *= pow(D[i-1], D[i], MOD)
            ans %= MOD
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in D:
            if i > 1:
                ans *= pow(D[i-1], D[i], MOD)
                ans %= MOD
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n, *d = map(int, sys.stdin.buffer.read().split())
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in D:
            if i:
                ans *= pow(D[i-1], D[i], MOD)
                ans %= MOD
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(sys.stdin.buffer.readline())
    d = list(map(int, sys.stdin.buffer.readline().split()))
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in range(1, n + 1):
            ans *= pow(D[i-1], D[i], MOD)
            ans %= MOD
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(sys.stdin.buffer.readline())
    d = list(map(int, sys.stdin.buffer.readline().split()))
    D = Counter(d)
    if D[0] != 1:
        print(0)
    else:
        ans = 1
        for i in range(1, n + 1):
            ans *= pow(D[i-1], D[i], MOD)
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(sys.stdin.buffer.readline())
    d = list(map(int, sys.stdin.buffer.readline().split()))
    D = Counter(d)
    if D[0] != 0:
        print(0)
    else:
        ans = 1
        for i in range(1, n + 1):
            ans *= pow(D[i-1], D[i], MOD)
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(sys.stdin.buffer.readline())
    d = list(map(int, sys.stdin.buffer.readline().split()))
    D = Counter(d)
    if 0 not in d:
        print(0)
    else:
        ans = 1
        for i in range(1, n + 1):
            ans *= pow(D[i-1], D[i], MOD)
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    n = int(sys.stdin.buffer.readline())
    d = list(map(int, sys.stdin.buffer.readline().split()))
    D = Counter(d)
    if 0 not in d:
        print(0)
    else:
        ans = 1
        for i in D:
            if i >= 1:
                ans *= pow(D[i-1], D[i], MOD)
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353


def main():
    n = int(input())
    d = list(map(int, input().split()))
    D = Counter(d)
    if 0 not in d:
        print(0)
    else:
        ans = 1
        for i in D:
          if i >= 2:
            ans *= pow(D[i-1], D[i], MOD)
        print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
mod = 998244353
max_v = 0
for v in list(map(int, input().split())):
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)
# 0はひとつだけ
if 0 not in d or d[0] > 1:
    print(0)
    exit()
ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
mod = 998244353
max_v = 0
for v in list(map(int, input().split())):
    if v not in d:
        d[v] = 1
    else:
        d[v] += 1
    max_v = max(max_v, v)

ans = 1
# 木を作ることができるならば1~max_vまでの数字がそれぞれ1つ以上存在する
for i in range(1, max_v + 1):
    if i not in d or i - 1 not in d:
        ans *= 0
    else:
        ans *= pow(d[i - 1], d[i], mod)
        ans %= mod
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

if a[0] == 1 and d[0] == 0:
    ans = 1
    for i in range(1, n):
        ans *= a[i-1]**a[i]

    print(ans)
else:
    print(0)

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

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

print(ans)

Submission status: Wrong Answer

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

a = {}
for i in range(n):
    if d[i] in a:
        a[d[i]] += 1
    else:
        a[d[i]] = 1

if d[0] == 0 and a[0] == 1:
    a = sorted(a.items())
    cnt = 1

    for i in range(1, len(a)):
        cnt *= a[i-1][1]**a[i][1]

    print(cnt)
else:
    print(0)

Submission status: Wrong Answer

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