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

d = [0] * n

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

flag = 0
ans = 1

for i in range(n):
    if d[i] == 0:
        print(0)
        exit()
    elif i == 0 or i == 1:
        flag += d[i]
    else:
        ans *= d[i-1] ** d[i] % 998244353
        flag += d[i]
        if flag == n:
            break

print(ans)

Submission status: Wrong Answer

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

c=Counter(D)
ans=1


for v in c:
  if c==0:
    continue
  else:
    ans*=v*c[v]
    
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().strip().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == 0 or D[i] > D[i-1] + 1:
      return 0
    if D[i] == D[i-1]:
      curCount += 1
    if D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == 0 or D[i] > D[i-1] + 1:
      return 0
    if D[i] == D[i-1]:
      curCount += 1
    if D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == D[i-1]:
      curCount += 1
    elif D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
    else:
      return 0
    result = result * preCount
    result = result%998244353
    #print(pre, curCount, preCount, result)
  return result
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0] * (max(Ds)+1)
for D in Ds:
    counter[D] += 1
ans = 1
if counter[0] != 1:
    print(0)
else:
    for i in range(1,max(Ds)+1):
        ans *= (counter[i-1] ** counter[i])
        ans %= CONST_DIVSOR
    print(ans % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0] * (max(Ds)+1)
for D in Ds:
    counter[D] += 1
ans = 0
for i in range(max(Ds)+1):
    if i == 0:
        if counter[i] == 1:
            ans = 1
        else:
            break
    else:
        ans *= (counter[i-1] ** counter[i])
        ans %= CONST_DIVSOR
    # print(i,total,prenumi,cnt)

print(ans % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0] * N
for D in Ds:
    counter[D] += 1
ans = 0
for i in range(max(Ds)+1):
    if i == 0:
        if counter[i] == 1:
            ans = 1
        else:
            break
    else:
        ans *= (counter[i-1] ** counter[i]) % CONST_DIVSOR
    # print(i,total,prenumi,cnt)

print(ans % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(D):
  if D[0] != 0:
    return 0
  result = 1
  curCount = 1
  preCount = 1
  for i in range(1, len(D)):
    if D[i] == D[i-1]:
      result = result * preCount
      curCount += 1
    elif D[i] == D[i-1] + 1:
      preCount = curCount
      curCount = 1
      result = result * preCount
    else:
      return 0
    #print(pre, curCount, preCount, result)
  return result%998244353
 
print(calc(D))

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))
counter = [0] * N
for D in Ds:
    counter[D] += 1
total = 0
cnt = 0
prenumi = 0
for i in range(max(Ds)+1):
    if i == 0:
        if counter[i] == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = counter[i]
        if numi != 0:
            case = 1
            for j in range(numi):
                case = (case * prenumi) % CONST_DIVSOR
            total = (total * case) % CONST_DIVSOR
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break

print(total % CONST_DIVSOR)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n1 = int(input()) - 1
d = list(map(int, input().strip().split()))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    max_path = max(d)
    flag = True
    v = [0 for i in range(max_path)]
    for i in d[1:]:
        v[i-1] += 1

    if 0 in v:
        flag = False

    if flag:
        num = 1
        hh = 1

        for h in v:
            num *= hh ** h
            num = num % mod
            hh = h

        print(num)

    else:
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
mod = 10**9 + 7
from collections import Counter
c = Counter(d)
if c[0] != 1 or d[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(1,max(d) + 1):
        ans *= c[i-1]**c[i]
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = sorted(list(map(int,input().split())))
mod = 10**9 + 7
from collections import Counter
c = Counter(d)
if c[0] == 0:
    print(0)
else:
    ans = 1
    for i in range(1,max(d) + 1):
        ans *= c[i-1]**c[i]
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
# print(D)
 
def calc(N, D):
  counts = [0]
  preNum = 0
  for i in D:
    if i == preNum:
      counts[-1] += 1
    elif i == preNum + 1:
      counts.append(1)
    else:
      return 0
    preNum = i
  result = 1
  for i in range(len(counts)-1):
    result = result * pow(counts[i+1], counts[i])
  return result%998244353
 
print(calc(N, D))

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())

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

waru = 998244353

c = collections.Counter(d)

ans =1

cmax =max(c.keys())
if d[0] != 0:
    print(0)
else:
    for i in range(1,cmax+1):
        ans *= c[i-1]** c[i]

print(ans % waru)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
q=[]
#from collections import Counter
#q=Counter(d)

for i in range(max(d)+1):
    q.append(d.count(i))
print(q)

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

ans=1
for i in range(1,max(d)+1):
    ans*=q[i-1]**q[i]
    if ans == 0:
        break
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])

if DD[0] != 0:
    print(0)
elif D[0][1] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(D)-1):
        ans *= D[i][1]**D[i+1][1]
        ans %= 998244353 
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])

if DD[0] != 0:
    print(0)
elif D[0][1] != 1:
    print(0)
else:
    ans = 1
    for i in range(len(D)-1):
        ans *= D[i][1]**D[i+1][1]
    print(ans%998244353)

Submission status: Wrong Answer

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

def main():
    N = int(input())
    D = list(map(int, input().split()))
    if D[0] != 0:
        print(0)
        exit()
    Dnum = [0] * N
    for i in D:
        Dnum[i] += 1
    if Dnum[0] != 1:
        print(0)
        exit()
    ans = 1
    num = 0
    for i in range(N-1):
        if num == N:
            break
        else:
            ans *= Dnum[i] ** Dnum[i+1]
    print(ans)


if __name__ == '__main__': main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])

ans = 0
if 1 == DD.count(0):
    ans = 1
    for i in range(1, len(D)-1):
        ans *= D[i][1]**D[i+1][1]
    print(ans)
        
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
DD = list(map(int, input().split()))
D = sorted(dict(Counter(DD)).items(), key=lambda x:x[0])

ans = 0
if 1 == DD.count(0):
    ans = 1
    for i in range(1, len(D)-1):
        print(D[i][1], D[i+1][1])
        ans *= D[i][1]**D[i+1][1]
    print(ans)
        
else:
    print(ans)

Submission status: Wrong Answer

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

from collections import Counter
q=Counter(D)

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

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

Submission status: Wrong Answer

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

ans = 1
if D[0] == 0 and D.count(0) == 1:
  for i in range((N ** 2 - N) // 2):
    if D.count(i + 1) > 0:
      ans *= D.count(i + 1) ** D.count(i + 2)
    else:
      break
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
lis = list(map(int,input().split()))
count_ls = [0]*max(lis)
Sum = 1
if lis[0] != 0:
  print(0)
else:
  for i in range(1,N):
    if lis[i] == 0:
      Sum = 0
    else:
      count_ls[lis[i]-1] += 1
  for j in range(len(count_ls)-1):
    Sum *= count_ls[j] ** count_ls[j+1]
  print(Sum)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
ans=1
if D[0]!=0:
    print(0)
else:
    for i in range(max(D)-1):
        ans*=D.count(i+1)**D.count(i+2)
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)

ans = 1
for i in range(max(d) + 1):
    if i not in c:
        ans = 0

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

if c[0][0] != 0:
    ans = 0

for i in range(1, len(c)):
    if c[i][0] < 0:
        ans = 0
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
 
from collections import Counter
q=Counter(d)
 
ans = 1
if q[0]!=0 or d[0]!=0:
  print(0)
  exit()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
 
from collections import Counter
q=Counter(d)
 
ans = 1
if min(d)!=0 or d[0]!=0:
  print(0)
  exit()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

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

from collections import Counter
q=Counter(d)

ans = 1
if min(d) != 0 or d[0] != 0:
  ans = 0
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

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

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    ans %= 998244353
    if ans == 0:
        jug = False
    
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

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

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    ans %= 998244353
    
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)

jug = True
for i in range(max(d) + 1):
    if i not in c:
        jug = False

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

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# key:value 辺の長さ:頂点の数
q=Counter(d)

ans = 1
if q[0] == 0:
  print(0)
  exit()
d.sort()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# key:value 辺の長さ:頂点の数
q=Counter(d)

ans = 1
if min(d) != 0:
  ans = 0
d.sort()
for i in range(1,max(d)+1):
  ans *= pow(q[i-1],q[i])
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# key:value 辺の長さ:頂点の数
q=Counter(d)

ans = 1
if min(d) != 0:
  ans = 0
d.sort()
for i in range(1,max(d)+1):
  ans *= q[i-1]**q[i]
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

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

s = list(set(D))

ans = 1
if min(D) == 0 and sum(x > 0 for x in D) == len(D) - 1:
  for i in range(len(s) - 2):
    if D.count(s[i + 1]) > 1:
      ans *= D.count(s[i + 1]) ** D.count(s[i + 2])
  print(ans)    
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
 
ans = 1
if min(d) != 0:
  ans = 0
d.sort()
for i in range(1,max(d)+1):
  ans = ans * pow(d.count(i-1),d.count(i))
  if ans == 0:
    break
print(ans%998244353)

Submission status: Wrong Answer

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

d = sorted(D)
s = list(set(D))

ans = 1
for i in range(len(s) - 2):
  if d.count(s[i + 1]) > 1:
    ans *= d.count(s[i + 1]) ** d.count(s[i + 2])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
d = (int(s) for s in input().split())
if next(d) != 0:
    print(0)
    quit(0)
c = Counter(d)
if c[0] != 1:
    print(0)
    quit(0)
print(reduce(lambda x, y: x * y, (c[k - 1] ** x if k > 1 else 1 for k, x in c.items()), 1) % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
d = (int(s) for s in input().split())
if next(d) != 0:
    print(0)
    quit(0)
c = Counter(d)
print(reduce(lambda x, y: x * y, (c[k - 1] ** x if k > 1 else 1 for k, x in c.items()), 1) % 998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
maxd=max(d)
import collections
counter=collections.Counter(d)
if d[0]!=0 or counter[0]!=1:
  print(0)
else:
  a=1
  ans=1
  for i in range(1,maxd+1):
    if i not in counter:
      print(0)
      break
    else:
      b=counter[i]
      ans*=(a**b)
      a=b
  else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math


def solve(*args: str) -> str:
    _ = int(args[0])
    D = list(map(int, args[1].split()))

    max_d = max(D)

    nodes = [0]*(max_d+1)
    for d in D:
        nodes[d] += 1

    ret = 0
    if D[0] == 0 and nodes.count(0) == 0 and nodes[0] == 1:
        ret = 1
        for i in range(2, max_d+1):
            h = math.factorial(nodes[i-1]+nodes[i]-1)
            h //= math.factorial(nodes[i])
            ret *= h

    return str(ret % 998244353)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from functools import reduce
n = int(input())
d = [int(s) for s in input().split()]
c = Counter(d)
print(reduce(lambda x, y: x * y, (c[x - 1] for x in d[1:]), 1) if c[0] == 1 and d[0] == 0 else 0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()] 
if a[0]!=0 : 
     print (0%998244353)
else:
    if a[0]!=1:
        print (0%998244353)
    else :
        a = Counter(a)
        ans = 1
        for i in range(1,len(a)-1): 
            ans*=a[i]**a[i+1]
        print(ans%998244353)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math


def solve(*args: str) -> str:
    _ = int(args[0])
    D = list(map(int, args[1].split()))

    max_d = max(D)

    nodes = [0]*(max_d+1)
    for d in D:
        nodes[d] += 1

    ret = 0
    if nodes.count(0) == 0 and nodes[0] == 1:
        ret = 1
        for i in range(2, max_d+1):
            h = math.factorial(nodes[i-1]+nodes[i]-1)
            h //= math.factorial(nodes[i])
            ret *= h

    return str(ret % 998244353)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

n=int(input())
l=list(map(int,input().split()))
l.sort()
if l[0]!=0:
    print(0)
elif n==1:
    print(1)
else:
    c=1
    last=0
    check=0
    setl=set(l)
    setl=list(setl)
    for _ in setl[1:]:
        if _!=last+1:
            print(0)
            sys.exit()
        last+=1
    m=[]
    last=0
    num=1
    for i in range(1,n):
        if l[i]!=last:
            m.append(c%998244353)
            c=1
            last+=1
        else:
            c+=1
        if i==(n-1):
            m.append(c)
    for k in range(1,len(m)):
        num*=m[-k-1]**m[-k]
        num%=998244353
    print(num)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter
n = int(input())
d = [int(s) for s in input().split()]
c = Counter(d)
ds = [0] * (max(c.keys()) + 1)
for k, v in c.items():
  ds[k] = v
print(reduce(lambda x, y: x * y, (x ** y for x, y in zip(ds[:-1], ds[1:])), 1) if ds[0] == 1 and d[0] == 0 else 0)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter
n = int(input())
c = Counter(int(s) for s in input().split())
ds = [0] * (max(c.keys()) + 1)
for k, v in c.items():
  ds[k] = v
print(reduce(lambda x, y: x * y, (x ** y for x, y in zip(ds[:-1], ds[1:])), 1) % 998244353 if ds[0] == 1 else 0)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter
n = int(input())
c = Counter(int(s) for s in input().split())
ds = [0] * (max(c.keys()) + 1)
for k, v in c.items():
  ds[k] = v
print(reduce(lambda x, y: x * y, (x ** y for x, y in zip(ds[:-1], ds[1:])), 1) if ds[0] == 1 else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * N
ans = 1
if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(N):
    if (i > 0):
        ans *= (count[i - 1] ** count[i]) % 998244353
        ans %= 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math


def solve(*args: str) -> str:
    _ = int(args[0])
    D = list(map(int, args[1].split()))

    nodes = [D.count(d) for d in range(max(D)+1)]

    ret = 1
    for i, c in enumerate(nodes):
        if i < 2:
            ret *= 1 if 0 < c else 0
        else:
            h = math.factorial(nodes[i-1] + nodes[i]-1)
            h //= math.factorial(nodes[i])
            ret *= h

    return str(ret % 998244353)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * N
ans = 1
if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(1, N):
    ans *= (count[i - 1] ** count[i]) % 998244353
    ans %= 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * (N)
ans = 1
if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(1, N):
    ans *= (count[i - 1] ** count[i]) % 998244353
    ans %= 998244353

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * (N)
ans = 1
if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(N - 1):
    ans *= (count[i] ** count[i + 1]) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * (N)
ans = 1
if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(1, N - 1):
    ans *= (count[i] ** count[i + 1]) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

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

print(ans % 998244353)

Submission status: Wrong Answer

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

def ruijo(a, b, mod):
    x = 1    
    for i in range(b):
        x = ((x%mod) * (a%mod)) % mod     
    return x

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

Sum = 1

if x[0] != 1:
    print(0)
else:

    for i in range(len(x)):
    
        if i != 0:
            Sum = (Sum * ruijo(x[i - 1], x[i], 998244353))%998244353
    
    print(Sum%998244353)

Submission status: Wrong Answer

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

def ruijo(a, b, mod):
    x = 1    
    for i in range(b):
        x = ((x%mod) * (a%mod)) % mod     
    return x

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

Sum = 1

if x[0] != 1:
    print(0)
else:

    for i in range(len(x)):
    
        if i != 0:
            Sum = (Sum * ruijo(x[i - 1], x[i], 998244353))%998244353
        else:
            Sum = (Sum * (x[i]%998244353))%998244353
    
    print(Sum%998244353)

Submission status: Wrong Answer

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

def ruijo(a, b, mod):
    x = 1    
    for i in range(b):
        x = ((x%mod) * (a%mod)) % mod     
    return x

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

Sum = 1

if x[0] > 1:
    print(0)
else:

    for i in range(len(x)):
    
        if i != 0:
            Sum = (Sum * ruijo(x[i - 1], x[i], 998244353))%998244353
        else:
            Sum = (Sum * (x[i]%998244353))%998244353
    
    print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
# 再帰関数の最大再帰回数を変更
import sys
sys.setrecursionlimit(1000000)

# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（１つ前の深さの頂点の数 ^ 現在の深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (deep[now - 1] ** deep[now]))

# 最後に割る数の定数
JOSU = 998244353

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

# 深さをメモするため、Dの最大値 + 1の数の配列を用意
# 例：深さの最大が2なら、0, 1, 2の3つが必要
deep = [0] * (max(D) + 1)

# 各深さの頂点の数を記録
for i in range(N):
    deep[D[i]] += 1

# 深さ0の頂点が1以外なら、木ができないため0を返す
if deep[0] != 1:
    print(0)
# ためし
elif min(deep) == 0:
    print(0)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)

# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（１つ前の深さの頂点の数 ^ 現在の深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (deep[now - 1] ** deep[now]))

# 最後に割る数の定数
JOSU = 998244353

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

# 深さをメモするため、Dの最大値 + 1の数の配列を用意
# 例：深さの最大が2なら、0, 1, 2の3つが必要
deep = [0] * (max(D) + 1)

# 各深さの頂点の数を記録
for i in range(N):
    deep[D[i]] += 1

# 深さ0の頂点が1以外なら、木ができないため0を返す
if deep[0] != 1:
    print(0)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
d=[int(i) for i in input().split()]
mod = 998244353

d=sorted(d)
ans = 1

if d[0]!=0:
    print(0)
    exit()
if d[1]==0:
    print(0)
    exit()
    
dic = defaultdict(int)
dic[0] = 1
for i in d[1:]:
    ans *= dic[i-1]
    dic[i] += 1
print(ans % mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
d=[int(i) for i in input().split()]
mod = 998244353

d=sorted(d)
ans = 1


    
dic = defaultdict(int)
dic[-1] = 1
for i in d:
    ans *= dic[i-1]
    ans = ans % mod
    dic[i] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n=int(input())
d=[int(i) for i in input().split()]
mod = 998244353

d=sorted(d)
ans = 1

if d[0]!=0:
    print(0)
    exit()
if d[1]==0:
    print(0)
    exit()
    
dic = defaultdict(int)
dic[0] = 1
for i in d[1:]:
    ans *= dic[i-1]
    ans = ans % mod
    dic[i] += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
#入力
n = int(input())
d = list(map(int,input().split()))

a = []
if d[0] != 0:
	ans = 0
else :
	ans = 1
	for i in range(1,n-1):
		a = d.count(i)
		b = d.count(i-1)
		ans = ans * pow(b,a)

print(ans)

Submission status: Wrong Answer

Solution code:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=d[0]<1
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Submission status: Wrong Answer

Solution code:
_,d=open(0)
*d,=map(int,d.split())
e=[0]*-~max(d)
for i in d:e[i]+=1
a=e[0]==1
for x,y in zip(e,e[1:]):a*=x**y
print(a%998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())

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

sum = 0

x.pop(0)

count = 1
for i in range(len(x)):
    if x[i][0] != count:
        print(0)
        exit()
    if i == 0:
        pre_num = 1
    else:
        pre_num = x[i-1][1]
    forward_num = x[i][1]
    cmb = pre_num**forward_num
    ans *= cmb
    ans = ans % num
    count += 1
    sum += x[i][1]

if sum != n-1:
    print(0)
    exit()

print(ans)

Submission status: Wrong Answer

Solution code:

import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
from collections import Counter
cs=Counter(d)
b=list(cs.values())
c=list(cs.keys())
#print(b,c)
if c!=[i for i in range(max(c)+1)]:
	print(0)
	sys.exit()
t=1
for i in range(len(b)-1):
	t*=b[i]**b[i+1]
	t%=998244353
print(t)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
d=map(int,raw_input().split())
c=[0]*n
for x in d:
  c[x] += 1
count = 1
mod = 998244353
for i in xrange(max(d)):
  count *= pow(c[i],c[i+1],mod)
  count %= mod
print count

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

sum = 0

x.pop(0)

count = 1
for i in range(len(x)):
    if x[i][0] != count:
        print(0)
        exit()
    if i == 0:
        pre_num = 1
    else:
        pre_num = x[i-1][1]
    forward_num = x[i][1]
    cmb = pre_num**forward_num
    ans *= cmb
    ans = ans % num
    count += 1
    sum += x[i][1]

if sum != n-1:
    print(0)
    exit()

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1;f=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if f*2<s:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
  f*=2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

x.pop(0)

count = 1
for i in range(len(x)):
    if x[i][0] != count:
        print(0)
        exit()
    if i == 0:
        pre_num = 1
    else:
        pre_num = x[i-1][1]
    forward_num = x[i][1]
    cmb = pre_num**forward_num
    ans *= cmb
    ans = ans % num
    count += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

x.pop(0)

for i in range(len(x)):
    if i == 0:
        pre_num = 1
    else:
        pre_num = x[i-1][1]
    forward_num = x[i][1]
    cmb = pre_num**forward_num
    ans *= cmb
    ans = ans % num

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n or pre*2<s:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1;fg=1
for i,(n,s) in enumerate(l):
  if i!=n or fg<s:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
  fg*=2
print(ans)