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())
array = list(map(int, input().split()))
ans = 1
if array[0] == 1:
    print(0)
    exit()
for i in range(1,N):
    ans *= array[i] % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = input().split()
D = np.array(D).astype(int)
if D[0]!=0:
  print(0)
else:
  D = np.sort(D) 
  max_depth = np.max(D)
  min_depth = np.min(D)
  if D[1]!=1:
    print(0)
  elif min_depth > 0:
    print(0)
  elif (np.diff(D) > 1).sum() > 0:
    print(0)
  else:
    out = 1
    idx = np.hstack([np.where(np.diff(D) == 1)[0], N-1])
    num = np.diff(idx)
    for i in np.arange(1, len(num)):
      out *= np.power(num[i-1], num[i])
      out = out%998244353
    print(out%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
ans = 1
if array[0] == 1:
    print(0)
    exit()
for i in range(1,N):
    ans *= array[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:
  print(0)
else:
  if a.count(0)!=1:
    print(0)
  else:
    b=[1]
    for i in range(1,max(a)+1):
    	b.append(a.count(i))
    count=1
    for i in range(len(b)-1):
      count=count*(b[i]**b[i+1])
    print(count)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))


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

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

print(lin)

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

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
ans = 1
for i in range(N):
    ans *= array[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
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):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
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+1):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Wrong Answer

Solution code:
M = 998244353

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

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

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
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+1):
  if D[i] == 0:
    break
  else:
    cnt *= D[i] ** D[i+1]
print(cnt % MOD)

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

cnt = Counter(d)
print(cnt)

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

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(N):
    d[dl[i]] += 1

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

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

ans = 1
for i in range(len(d) - 1, 0, -1):
    #if d[i][0] - 1 == d[i - 1][0]:
    ans *= (d[i - 1][1] ** d[i][1])
    ans = ans % INF
    #else:
    #    print(0)
    #    sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a[0]!=0:
  print(0)
else:
  if a.count(0)!=1:
    print(0)
  else:
    b=[1]
    for i in range(1,max(a)+1):
      if a.count(i)==0:
        print(0)
        break
      else:
        b.append(a.count(i))
    count=1
    for i in range(len(b)-1):
      count=count*(b[i]**b[i+1])
    print(count)

Submission status: Wrong Answer

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:
    break
  else:
    cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = input().split()
D = np.array(D).astype(int)
if D[0]!=0:
  print(0)
elif D[1]!=1:
  print(0)
else:
  D = np.sort(D) 
  max_depth = np.max(D)
  min_depth = np.min(D)
  if min_depth > 0:
    print(0)
  elif (np.diff(D) > 1).sum() > 0:
    print(0)
  else:
    out = 1
    idx = np.hstack([np.where(np.diff(D) == 1)[0], N-1])
    num = np.diff(idx)
    for i in np.arange(1, len(num)):
      out *= np.power(num[i-1], num[i])
      out = out%998244353
    print(out%998244353)

Submission status: Wrong Answer

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

# bucket
lst = [[] for i in range(n)]
ans = 1
sum = 1
P = 998244353
if d[0] != 0:
    print(0)
    quit()
else:
    for i in range(n):
        if d[i] == 0 and i != 0:
            print(0)
            quit()
        lst[d[i]].append(i + 1)

    tmp = len(lst[1])
    for i in range(1, n):
        if len(lst[i]) == 0:
            if sum != n:
                print(0)
                quit()
        sum += len(lst[i])
        if i == 1:
            continue
        ans *= tmp ** len(lst[i]) % P
        tmp = len(lst[i])
    print(ans)

Submission status: Wrong Answer

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):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)

Submission status: Wrong Answer

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: Wrong Answer

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

if idx[0] == 0:
    print(0)
else:
    for i in range(n):
        if idx[i] == 0:
            pre = 0
        else:
            if pre == 0:
                print(0)
                break
            else:
                ans *= pre**idx[i]
            pre = idx[i]
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
D = input().split()
D = np.array(D).astype(int)
D = np.sort(D)
 
max_depth = np.max(D)
min_depth = np.min(D)
if min_depth > 0:
  print(0)
elif (np.diff(D) > 1).sum() > 0:
  print(0)
elif D[0]!=0:
  print(0)
elif D[1]!=1:
  print(0)
else:
  out = 1
  idx = np.hstack([np.where(np.diff(D) == 1)[0], N-1])
  num = np.diff(idx)
  for i in np.arange(1, len(num)):
    out *= np.power(num[i-1], num[i])
    out = out%998244353
  print(out%998244353)

Submission status: Wrong Answer

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

n = int(input())
dd = list(map(int, input().split()))
ans = 1
first = dd.pop(0)

if first != 0:
    print(0)
    exit()

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0] +1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]

print(point%998244353)

Submission status: Wrong Answer

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

if idx[0] == 0:
    print(0)
else:
    for i in range(n):
        if idx[i] == 0:
            pre = 0
        else:
            if pre == 0:
                print(0)
                break
            else:
                ans *= pre**idx[i]
            pre = idx[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

point = 1
for i in range(1,len(lin)):
    if lin[i][1] <1:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

print(lin)
point = 1
for i in range(1,len(lin)):
    if lin[i][1] <1:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

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

if len(d) == 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(d) - 1, 0, -1):
    if d[i][0] - 1 == d[i - 1][0]:
        ans *= (d[i - 1][1] ** d[i][1])
        ans = ans % INF
    else:
        print(0)
        sys.exit()

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
MOD = 998244353
def main():
    n = int(input())
    cnt = {}
    for item in map(int, input().strip().split()):
        cnt.setdefault(item, 0)
        cnt[item] += 1
    result = 1
    for i in range(max(cnt) + 1):
        if i not in cnt:
            print("0")
            return

    if cnt.get(0, 0) != 1:
        print("0")
        return
    for key in cnt:
        if key == 0:
            continue
        # every level node can connect to every parent's node
        # therefore each level provides parent's count to the current count
        # different dispositions
        result = result * pow(cnt.get(key - 1, 0), cnt[key], MOD) % MOD
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

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

if len(d) == 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(d) - 1, 0, -1):
    if d[i][0] == d[i - 1][0] - 1:
        ans *= (d[i - 1][1] ** d[i][1])
        ans = ans % INF
    else:
        print(0)
        sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0] +1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

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

if len(d) == 1:
    print(0)
    sys.exit()

ans = 1
for i in range(len(d) - 1, 0, -1):
    ans *= (d[i - 1][1] ** d[i][1])
    ans = ans % INF

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
c = Counter(map(int, input().split()))
if c[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, len(c)):
    if c[i] == 0:
        print(0)
        exit()
    ans *= pow(c[i - 1], c[i], MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
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.get(0, 0) != 1:
        print("0")
        return
    for key in cnt:
        if key == 0:
            continue
        # every level node can connect to every parent's node
        # therefore each level provides parent's count to the current count
        # different dispositions
        result = result * pow(cnt.get(key - 1, 0), cnt[key], MOD) % MOD
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

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

if len(d) == 1:
    print(0)
    sys.exit()

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

print(ans % INF)

Submission status: Wrong Answer

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

mod = 998244353

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

from collections import Counter

counter = Counter(d_list)


prev = 0
max_d = max(d_list)
ans = 1
for i in range(1, max_d + 1):
    if i == 1:
        if counter[i] != 0:
            ans = 1
        else:
            print(0)
            exit()
    else:
        if counter[i] != 0:
            ans *= prev ** counter[i]
            ans %= mod
        else:
            print(0)
            exit()
    prev = counter[i]

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    D=list(map(int,input().split()))
    c=collections.Counter(D)
    k=list(c.keys())
    v=list(c.values())
    ans=1 if c[0] == 1 and max(k) == len(k)-1 else 0
    for i in range(max(k)):
        ans*=c[i]**c[i+1]
        ans%=998244353
        if ans == 0:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
INF = 998244353
N = int(input())
dl = list(map(int, input().split()))
if dl[0] != 0:
    print(0)
    sys.exit()
d = defaultdict(int)

for i in range(1, N):
    d[dl[i]] += 1

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

if len(d) == 1:
    print(0)
    sys.exit()

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

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
c = Counter(sorted(map(int, input().split())))
if c[0] != 1:
    print(0)
    exit()
ans = 1
for i, j in zip(list(c.keys()), list(c.keys())[1:]):
    if i + 1 != j:
        print(0)
        exit()
    ans *= c[i]**c[j]
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
c = Counter(map(int, input().split()))
if c[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, len(c)):
    if c[i] == 0:
        print(0)
        exit()
    ans *= c[i - 1]**c[i]
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

point = 1
for i in range(1,len(lin)):
    if lin[i][0] == 0:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

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.get(0, 0) != 1:
        print("0")
        return
    for key in cnt:
        if key == 0:
            continue
        # every level node can connect to every parent's node
        # therefore each level provides parent's count to the current count
        # different dispositions
        for _ in range(cnt[key]):
            result *= cnt.get(key - 1, 0)
            result %= 998244353
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
c = Counter(map(int, input().split()))
if c[0] == 0:
    print(0)
    exit()
ans = 1
for i in range(1, len(c)):
    if c[i] == 0:
        print(0)
        exit()
    ans *= c[i - 1]**c[i]
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    D=list(map(int,input().split()))
    c=collections.Counter(D)
    k=list(c.keys())
    v=list(c.values())
    ans=1 if c[0] == 1 else 0
    for i in range(max(k)):
        ans*=c[i]**c[i+1]
        ans%=998244353
        if ans == 0:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353


n = INT()
d = MAP()

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

l = [0]*(max(d)+1)
for i in d:
    l[i]+=1

ans=1
for i in range(1,max(d)+1):
    ans*=pow(l[i-1],l[i],MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
MOD = 998244353
n = int(input())
c = Counter(map(int, input().split()))
ans = 0 + (c[0] != 0)
for i in range(1, len(c)):
    ans *= c[i - 1]**c[i] if c[i - 1] > 0 else 0
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
d=list(map(int,input().split()))
dd=[]
count=1
if d[0]!=0:
    print(0)
    exit()
for i in range(1,max(d)+1):
    dd.append(d.count(i))
if dd[0]!=1:
    print(0)
    exit()
# print(dd)
for i in range(1,max(dd)+1):
    count *= pow(dd[i-1],dd[i],998244353)
print(count%998244353)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
ans = 0 + (c[0] != 0)
for i in range(1, len(c)):
    ans *= c[i - 1]**c[i] if c[i - 1] > 0 else 0
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    D=list(map(int,input().split()))
    c=collections.Counter(D)
    k=list(c.keys())
    v=list(c.values())
    ans=1 if c[0] == 1 else 0
    for i in range(max(k)):
        ans=(ans*(c[i]**c[i+1]))%998244353
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

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

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0] + 1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d_list = [int(d) for d in input().split(' ')]


def search(d_list):
    if d_list[0] != 0:
        return 0

    d_dict = defaultdict(int)
    unique_values = set()
    for d in d_list:
        d_dict[d] += 1
        unique_values.add(d)

    unique_num = len(unique_values)
    if not sum(unique_values) == unique_num * (unique_num - 1) / 2:
        return 0

    result = 1

    for v in unique_values:
        if v == 0:
            continue
        prev_node_num = d_dict.get(v-1)
        current_node_num = d_dict.get(v)

        result *= prev_node_num ** current_node_num
    return result % 998244353

print(search(d_list))

Submission status: Wrong Answer

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

result = 1

D.sort()

parent = 1
count = 1
tmp = 0

for i in range(1, len(D)):
  if D[i] - tmp > 1:
    print(0)
    break
  if D[i] == tmp:
    count += 1
  else:
    parent = count
    count = 1
  tmp = D[i]
  result *= parent

if D.count(0) == 1 and D[0] == 0:
  print(result % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    D=list(map(int,input().split()))
    c=collections.Counter(D)
    k=list(c.keys())
    v=list(c.values())
    ans=1
    for i in range(max(k)):
        ans=(ans*(c[i]**c[i+1]))%998244353
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

dkaisuu = collections.Counter(d)

ans = 1
for i in range(1,max(d)+1): # 1,2,3
    ans *= dkaisuu[i-1]**dkaisuu[i]
if d[0] == 0 and dkaisuu[0] == 1:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
d_list = [int(d) for d in input().split(' ')]


def search(d_list):
    if d_list[0] != 0:
        return 0

    d_dict = defaultdict(int)
    unique_values = set()
    for d in d_list:
        d_dict[d] += 1
        unique_values.add(d)

    unique_num = len(unique_values)
    if not sum(unique_values) == unique_num * (unique_num - 1) / 2:
        return 0

    result = 1

    for v in unique_values:
        if v == 0:
            continue
        prev_node_num = d_dict.get(v-1)
        current_node_num = d_dict.get(v)

        result *= prev_node_num ** current_node_num
    return result

print(search(d_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

result = 1

D.sort()

parent = 1
count = 1
tmp = 0

for i in range(1, len(D)):
  if D[i] == tmp:
    count += 1
  else:
    parent = count
    count = 1
  tmp = D[i]
  result *= parent

if D.count(0) == 1 and D[0] == 0:
  print(result % 998244353)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
anslist=[0 for i in range(n+1)]
for j in lists:
    anslist[j]+=1
if anslist[0]!=1:
    print(0)
else:
    ans=1
    for j in range(n):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import collections
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    D=list(map(int,input().split()))
    c=collections.Counter(D)
    k=list(c.keys())
    v=list(c.values())
    ans=len(k)//(max(k)+1)
    for i in range(len(k)-1):
        ans=ans*(c[i]**c[i+1])%998244353
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
li = list(map(int,input().split()))
 
ans = 1
ans_li = collections.Counter(li)

if not ans_li[0] == 1:
    print(0)
    exit()

for i in range(max(ans_li)+1):
    ans *= ans_li[i] ** ans_li[i+1]
    if ans_li[i] == 0:
        print(0)
        exit()
 
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
d=list(map(int,input().split()))
dd = collections.Counter(d)
if dd[0]!=1:
    print(0)
    exit()
count=1
for i in range(1,max(dd)+1):
    count = pow(dd[i-1],dd[i],99844353)
print(count%99844353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()

lin = []

for key, value in groupby(li):
    lin.append(len(list(value)))
if li[0] != 0:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if li[i] == 0:
        print(0)
        exit()
    point *= lin[i-1]**lin[i]
    point %= 998244353
    
print(point)

Submission status: Wrong Answer

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.get(0, 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
        for _ in range(cnt[key]):
            result = (result * cnt.get(key - 1, 0)) % 998244353
    print(result)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
N=int(input())
d=list(map(int,input().split()))
dd = collections.Counter(d)
if dd[0]!=1:
    print(0)
    exit()
count=1
for i in range(1,max(d)+1):
    count = pow(dd[i-1],dd[i],99844353)
print(count%99844353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()

lin = []

for key, value in groupby(li):
    lin.append(len(list(value)))
if li[0] != 0:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    point *= lin[i-1]**lin[i]
    point %= 998244353
    
print(point)