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: Runtime Error

Solution code:
import heapq
 
 
class Dijkstra:
 
    def __init__(self, rote_map, start_point, goal_point=None):
        self.rote_map = rote_map
        self.start_point = start_point
        self.goal_point = goal_point
 
    def execute(self):
        num_of_city = len(self.rote_map)
        dist = [10**16 for _ in range(num_of_city)]
        prev = [10**16 for _ in range(num_of_city)]
 		
        dist[self.start_point] = 0
        heap_q = []
        heapq.heappush(heap_q, (0, self.start_point))
        while len(heap_q) != 0:
            prev_cost, src = heapq.heappop(heap_q)
            if dist[src] < prev_cost:
                continue
            if src == self.goal_point:
                return prev_cost
 
            for dest, cost in self.rote_map[src].items():
                if dist[dest] > prev_cost + cost:
                    dist[dest] = prev_cost + cost
                    heapq.heappush(heap_q, (dist[dest], dest))
                    prev[dest] = src
        return -1
 
n,m=map(int, input().split()) 
route_map = [dict() for _ in range(n)]
 
for i in range(m):
    u, v, a = map(int, input().split())
    u, v = u - 1, v - 1
    route_map[u][v] = a
    
for i in range(n-1):
    u, v = i+1, i
    route_map[u][v] = 0
    
 
# ゴールまでの最短経路
print(Dijkstra(route_map,0,n-1).execute())

Submission status: Runtime Error

Solution code:
N = int(input())
 
for i in range(N):
    input_list = str(input()).split(" ")
 
if input_list[0] == '0':
    print(0)
else:
    print(1)

Submission status: Runtime Error

Solution code:
N = int(input())

for i in range(N):
    input_list = input().split(" ")

if input_list[0]:
    print(0)
else:
    print(1)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [1]
for i in range (n+1):
  a.append(0)
b = []
for i in range(n):
  x = int(input())
  a[x+1] += 1
  b.append(x)
ans = 1
for x in b:
  ans *= a[x]
  ans %= 998244353
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = [1]
for i in range (n):
  a.append(0)
b = []
for i in range(n):
  x = int(input())
  a[x+1] += 1
  b.append(x)
ans = 1
for x in b:
  ans *= b[x]
  ans %= 998244353
print(ans)

Submission status: Runtime Error

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

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
elif N == 1; print(0)
else:
  flg = True
  D.sort()
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

  if flg:
    for i in range(1,c):
      ans *= (A[i-1]%998244353)**A[i]
    print(ans%998244353)

  else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

for i in D:
  if i < N:
  	num_list[i] += 1

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:a]

ans = 1
if num_list[0] != 1:
  print(0)
elif len(num_list) == 1:
  print(0)
else:
  for i in range(len(num_list)):
    if i > 0 and num_list[i] == 0:
      break
    elif i > 0 and num_list[i] != 0:
      for j in range(num_list[i]):
      	ans = ans * num_list[i-1]
  print(ans % 998244353)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
MOD = 998244353
result = 1;
if A[0] != 0:
  print(0)
  exit()
m = {}
max_level = 0
for a in A:
  m.setdefault(a, 0)
  m[a] += 1
  max_level = max(max_level, a)

if m[0] >= 2:
  print(0)
  exit()

for i in range(max_level):
  result = (result * pow(m[i], m[i+1], MOD)) % MOD

print(result%MOD)

Submission status: Runtime Error

Solution code:
num_list = [0 for i in range(N)]

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

for i, num in enumerate(num_list):
  if i == 0:
    continue
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0 and num == 0:
      break
    elif i > 0 and num != 0:
      ans **= num
      ans *= num
  print(ans % 998244353)

Submission status: Runtime Error

Solution code:
N = int(input())

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

num_list = [0 for i in range(N)]

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

for i, num in enumerate(num_list):
  if num == 0:
    a = i
    break
    
num_list = num_list[:i]

ans = 1
if num_list[0] != 1:
  print(0)
else:
  for i, num in enumerate(num_list):
    if i > 0 and num == 0:
      break
    elif i > 0 and num != 0:
      ans **= num
      ans *= num
  print(ans % 998244353)

Submission status: Runtime Error

Solution code:
n = int(input().strip())
d = list(map(int, input().split()))
h = [0] * n
for x in d:
  h[x] += 1

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

if h[0] != 1 || d[0] != 0:
  ans = 0

print (ans)

Submission status: Runtime Error

Solution code:
import itertools

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

if 0 in li:
  li = itertools.Collection(li)
  li.sort(key = lambda x: x.key)
  c1 = li[0]
  ans = 0
  div = 998244353
  for c2 in li.values:
    ans *= c1**c2
    ans %= div
else:
  ans = 0
print(ans)

Submission status: Runtime Error

Solution code:
def calc(N, D):
    if D[0] != 0:
        return 0
    d = {}
    for Di in D:
        d[Di] = 1 + (d[Di] if Di in d else 0)
    if d[0] != 1:
        return 0
    result = 1
    for i in range(max(d.keys())):
        if d[i + 1] == 0:
            return 0
        result *= d[i] ** d[i + 1]
    return result


N = int(input())
D = [int(s) for s in input().split()]
print(calc(N, D))

Submission status: Runtime Error

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

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

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

for i in range(0,N-1):
  if abs(D[i] - D[i+1]) > 1:
    print(0)
    exit(0)

cnt = [0 for _ in range(N)]

for i in range(1,N):
  cnt[D[i]] += 1

ans = 1

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

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = i = 1
  x = c.get(i)
  while n > 1:
    n -= x
    r = r * pow(p, x, M) % M
    i += 1; p = x; x = c.get(i)
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = i = 1
  x = c.get(i)
  while x and i < n:
    p = x; i += 1; x = c.get(i); n -= x
    r = r * pow(p, x, M) % M
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = i = 1
  x = c.get(i)
  while x and i < n:
    r = r * pow(p, x, M) % M
    p = x; i += 1; x = c.get(i); n -= x
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = x = 1
  try:
    for i in range(1, n):
      p = x; x = c.get(i); n -= x
      r = r * pow(p, x, M) % M
  except ValueError:
    pass
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = x = 1
  for i in range(1, n):
    p = x
    try:
      x = c.get(i)
    except KeyError:
      break
    n -= x
    r = r * pow(p, x, M) % M
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
import sys
import collections

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

if D[0] != 0 or D[1] == 0:
    print(0)
    sys.exit()
DD = collections.Counter(D)
result = 1
for i in range(N - 1) - 1:
    if DD[i + 1] == 0:
        print(0)
        sys.exit()
    result *= DD[i] ** DD[i + 1]
print(result % 998244353)

Submission status: Runtime Error

Solution code:

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

ans=1


for v in D:
  if v==0 and D.index(v)==0:
    continue
  else:
    ans*=v
    
print(ans)

Submission status: Runtime Error

Solution code:
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: Runtime Error

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
D.sort()
pos = [-1 for i in range(N+2)]
def search():
    max = -1
    for i in range(N):
        if max + 1 < D[i]:
            return False
        else:
            if max < D[i]:
                max = D[i]
                pos[D[i]] = 1
            else:
                pos[D[i]] += 1
    return True

if search() :
    ans = 1
    for i in range(len(pos)):
        if pos[i] == 1 :
            if pos[i+2] == -1 :
                ans = ans
            else:
                while True :
                    i += 1
                    if pos[i] == 1 or pos[i] == -1 :
                        break
                    else:
                        ans *= pow(pos[i],pos[i+1])
    print(ans)


else :
    print(0)

Submission status: Runtime Error

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

from collections import Counter
q=Counter(d)

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: Runtime Error

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

from collections import Counter
q=Counter(d)

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

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

Submission status: Runtime Error

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

from collections import Counter
q=Counter(d)

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

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

Submission status: Runtime Error

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

from collections import Counter
q=Counter(d)

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

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

print(ans%998244353)

Submission status: Runtime Error

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])

ans = 1

if c[0][0] != 0:
    jug = False
else:
    for i in range(max(d)):
        if c[i][0] < 0:
            jug == False
        else:
            m = c[i][1]
            r = c[i+1][1]
            ans *= m ** r
            ans %= 998244353
            if ans == 0:
                jug = False
  
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math


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

    max_d = D[-1]

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

    ret = 1
    for i in range(max_d+1):
        if i < 2:
            ret *= 1 if 0 < nodes[i] 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: Runtime Error

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: Runtime Error

Solution code:
import numpy as np
import collections
input1 = list(map(int,input().split()))
input2 = list(map(int,input().split()))

N = input1[0]
D = input2

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

counter = collections.Counter(D)

ans = 1

D.sort()
D_numpy = np.array(D)
if (np.diff(D_numpy)<=1).prod():
  if counter[0] != 1:
    ans = 0
  else:
    for i in range(len(counter)):
      try:
        counter[i]
      ans *= counter[i]**counter[i+1]
      if ans >= 998244353:
        ans = ans%998244353

else:
  ans = 0



print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
import numpy as np
import collections
input1 = list(map(int,input().split()))
input2 = list(map(int,input().split()))

N = input1[0]
D = input2


counter = collections.Counter(D)

ans = 1

D.sort()
D_numpy = np.array(D)
if (np.diff(D_numpy)<=1).prod():
  if counter[0] != 1:
    ans = 0
  else:
    for i in range(len(counter)):
      try:
        counter[i]
      ans *= counter[i]**counter[i+1]
      if ans >= 998244353:
        ans = ans%998244353

else:
  ans = 0

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

print(ans)

Submission status: Runtime Error

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):
    ans *= (count[i] ** count[i + 1]) % 998244353

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(100000)

# 再帰関数で作る木の個数を返す
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: Runtime Error

Solution code:
# 再帰関数で作る木の個数を返す
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: Runtime Error

Solution code:
# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（現在の深さ ^ その深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (now ** 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)
# 深さ0の頂点のみなら、1を返す
elif len(deep) == 1:
    print(1)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)

Submission status: Runtime Error

Solution code:
# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（現在の深さ ^ その深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (now ** 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[D[0]] != 1:
    print(0)
# 深さ0の頂点のみなら、1を返す
elif len(deep) == 1:
    print(1)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)

Submission status: Runtime Error

Solution code:
# 再帰関数で作る木の個数を返す
def dfs(now, end, summary):
    # 終了条件
    if now == end:
        return summary
    # 1つ前の頂点時点で作ることのできる木の個数 *（現在の深さ ^ その深さの頂点の数）で再帰関数
    else:
        return dfs(now + 1, end, summary * (now ** 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[D[0]] != 1:
    print(0)
# 深さ0の頂点のみなら、1を返す
elif len(deep) == 1:
    print(1)
# それ以外なら各深さの辺のつけ方を計算して返す
else:
    print(dfs(1, len(deep), 1) % JOSU)

Submission status: Runtime Error

Solution code:
import collections
 
N=int(input())
D=list(map(int,input().split()))
 
c=collections.Counter(D)
 
max_D=max(D)
ans=1
previous_leaf=1
 
if D[0]!=0:
    ans=0
elif c[0]!=1:
    ans=0
else:
    for i in range(1,max_D+1):
        ans*=(previous_leaf**c[i])
        ans%=998244353
        previous_leaf=c[i]
 
print(ans)
import collections

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

c=collections.Counter(D)

max_D=max(D)
ans=1
previous_leaf=1

if D[0]!=0:
    ans=0
elif c[0]!=1:
    ans=0
else:
    for i in range(1,max_D+1):
        ans*=(previous_leaf**c[i])
        ans%=998244353
        previous_leaf=c[i]

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(map(list,co(map(int,input().split())).items())))
if 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:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Runtime Error

Solution code:
import sys
def I(): int(sys.stdin.readline())
def LI(): [int(x) for x in sys.stdin.readline().split()]
mod = 998244353


def main():
    N = I()
    A = LI()

    if A[0] != 0:
        return 0

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

    if DistCnt[0] != 1:
        return 0

    ans = 1
    for i in range(1,len(DistCnt)):
        ans *= pow(DistCnt[i-1],DistCnt[i],mod)
        ans %= mod
    return ans

if __name__ == "__main__":
    print(main())

Submission status: Runtime Error

Solution code:
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    for i in range(1, n + 1):
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
  except:
    pass
print((r, 0)[n > 1])
from collections import Counter
 
M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    for i in range(1, n + 1):
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
  except:
    pass
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
from collections import Counter
from itertools import count

M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    for i in count(1):
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
    except:
        pass
print((r, 0)[n > 1])

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn=2e5+10;
const ll mod=998244353;
ll num[mn];
ll po(ll a,ll b){
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod;
    return ans;
}
int main(){
    int n,i,x;
    scanf("%d",&n);
    ll ans=1;
    for(i=0;i<n;i++){
        scanf("%d",&x);
        if(i==0&&x!=0)ans=0;
        if(i!=0&&x==0)ans=0;
        num[x]++;
    }
    for(i=1;i<n;i++)ans=ans*po(num[i-1],num[i])%mod;
    printf("%lld",ans);
}

Submission status: Runtime Error

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10*5+100)]
ans = 1
mx = -1
for i in d:
    lis[i] += 1
    if i > mx:
        mx = i
if lis[0] != 1 or d[0] != 0:
    print(0)
for i in range(1, mx+1):
    for j in range(lis[i]):
        ans *= lis[i-1]
print(ans%998244353)

Submission status: Runtime Error

Solution code:
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
        break
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i]%M)
    else:
        print(ans%M)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
D = [int(n) for n in input().split(' ')]
 
if D[0] != 0:
    print(0)
else:
    D.sort()
    cnt = []
    for i in range(1, N):
        if D[i] == D[i-1]:
            cnt.append(cnt[-1])
        else:
            cnt.append(D.count(D[i-1]))
    ans = np.prod(cnt)
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
D = [int(n) for n in input().split(' ')]

if D[0] != 0:
    print(0)
else:
    D.sort()
    cnt = []
    for i in range(1, N):
        if D[i] == D[i-1]:
            cnt.append(cnt[-1])
        else:
            cnt.append(D.count(D[i-1]))
    ans = np.prod(cnt)
    print(ans)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
MOD=998244353
if D[0] != 0:
  print(0)
  exit()
D=collections.Counter(D)
if D[0] >= 2:
  pritn(0)
  exit()
cnt=1
for i in range(1,m):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using T = tuple<int, int, int>;

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  Dijkstra<ll> g(n);
  for (int i = 0; i < n - 2; i++) {
    g.addEdge(i + 1, i, 0);
  }
  for (int i = 0; i < m; i++) {
    int l, r, c;
    cin >> l >> r >> c, l--, r--;
    g.addEdge(l, r, c);
  }
  auto d = g.build(0);
  cout << ((d[n - 1] >= 0) ? d[n - 1] : -1) << endl;
}

Submission status: Runtime Error

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

for i in range(max(d)+1):
	x.append(d.count(i))
ans = 1
if d[0] == 0 and x[0] == 1:
	for i in range(1, len(x)):
		ans = ans * (x[i]**x[i+1])
else:
	ans = 0

print(ans%998244353)

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
D=list(map(int,input().split()))
D.sort()
m=d[-1]
MOD=998244353
if D[0] != 0 or D[0] >= 2:
  print(0)
  exit()
D=collections.Counter(D)
cnt=1
for i in range(1,m):
  if D[i] == 0:
    print(cnt % MOD)
    exit()
  else:
    cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Runtime Error

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

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

ans = 1
setD = list(set(d))
# setD.sort()



if d[0] > 0:
        print(0)
else:
        c = Counter(d)
        
        # for _d in d:
        #         if _d != 0:
        #                 # print(_d - 1)
        #                 print(c[_d - 1])
        #                 # print("---------------")
        #                 ans *= c[_d - 1]

        for _d in setD:
                if _d != 0:
                        ans *= c[_d - 1] ** c[_d]

        print(ans%998244353)

Submission status: Runtime Error

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

Submission status: Runtime Error

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)
    m.reverse=True
    ans=1
    i=0
    for i in range(len(m)-1):
        ans*=m[i+1]**m[i]%998244353
    print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    cnt = {}
    for item in map(int, input().strip().split()):
        cnt.setdefault(item, 0)
        cnt[item] += 1
    result = 1
    if cnt[0] != 1:
        print("0")
        return
    for key in cnt:
        if key == 0:
            continue
        # every level node can connect to every parent node
        # therefore each level provides parent's count to the current count
        # different dispositions
        result *= cnt.get(key - 1, 0)**cnt[key]
    print(result)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(DCounter.items()[1:]):
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N = int(input())
from collections import Counter
D = [int(i) for i in input().split()]
c = Counter(D)


if D[0] != 0:
  break
if c[0] != 1:
  print(0)
  quit()
if len(c.keys()) != max(c.keys())+1:
  print(0)
  quit()

  
res = 1
for i in range(1,1+max(c.keys())):
  res *= c[i-1]**c[i]
  res %= 998244353
print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(Dlist.items()):
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)

Submission status: Runtime Error

Solution code:
vfrom collections import Counter

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

count = Counter(d)

if d[0] != 0:
    print(0)
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print(0)
    
else:
    ans = 1
    tmp = 1
    for i in range(1, len(d)+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


    print(ans%998244353)

Submission status: Runtime Error

Solution code:
from collections import Counter

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

count = Counter(d)

if d[0] != 0:
    print(0)
    


#print(count[0])
#print(len(count))
#print(count.keys())
#print(count.items())
elif count[0] != 1:
    print(0)
    
else:
    ans = 1
    tmp = 1
    for i in range(1, len(d)+1):
        
        ans *= tmp**count[i]
        #print(ans)
        tmp = count[i]


print(ans%998244353)

Submission status: Runtime Error

Solution code:
n = int(inputs[0])
D = list(map(int, inputs[1].split()))

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

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
inputs = sys.stdin.readlines()

n = int(inputs[0]())
D = list(map(int, inputs[1]().split()))

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

Submission status: Runtime Error

Solution code:
import math
n = int(input())
d = list(map(int,input().split()))
d.sort()
a = len(set(d))
c = 0
b = 0
ans = 0

for i in range(1,a):
    c = b
    b = 0
    for j in range(n):
        if d[j] == i:
            b += 1
            ans += math.factorial(b)/math.factorial(c)
#print(int(ans))
print(998244353 % int(ans))