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= sorted(list(map(int, input().split())))
x=[0]*(d[n-1]+1)
k=0
for i in range(n):
    if d[i]==k:
        x[k]+=1
    elif d[i]==k+1:
        k+=1
        x[k]+=1
    else:
        break
#print(d)
#print(x)
if x[0]>=2:
    print(0)
else:
    a=1
    for i in range(d[n-1]):
        a*=(x[i]**x[i+1])%998244353
    print(a)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    l = {}
    for i in input().split():
        i = int(i)
        if i in l:
            l[i] += 1
        else:
            l[i] = 1
    
    count = 1
    m = max(l)
    if 0 not in l:
        print(0)
        exit()
    
    for i in range(1,m+1):
        if i in l:
            count *= l[i-1] ** l[i] % 998244353
        else:
            print(0)
            exit()
    
    print(count)
            
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ct = Counter(Ds)
M = max(ct)
if ct[0] != 1:
    print(0)
    exit()
ans = 1
for i in range(1, M+1):
    ans *= pow(ct[i-1], ct[i], MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353

def beki(x, n):
  if n == 0:
    return 1
  if n % 2 == 0:
    return beki(x * x % MOD, n // 2) % MOD
  else:
    return x * beki(x, n - 1) % MOD


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

ans = 1
cnt = 1
precnt = 1
if D[0] != 0:
    ans = 0
if N > 1 and D[-1] == 0:
    ans = 0

for i in range(N-1):
    if D[i] == D[i+1]:
        cnt += 1
    elif D[i] + 1 != D[i+1]:
        ans = 0
        break
    else:
        ans *= beki(precnt, cnt) % MOD
        precnt = cnt
        cnt = 1
        if (i == N-1):
            break
else:
    ans *= beki(precnt, cnt) % MOD
print(ans)

Submission status: Wrong Answer

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

if e[0] != 0:
  ans = 0
else:
  ce = Counter(e)
  sce = sorted(ce.items())
  # keyの数が連番であることを確認
  if sce[-1][0] != len(sce) - 1:
    ans = 0
  else:
    ans = 1
    pre = 1
    for i, j in sce:
      if pre != 1:
        ans = (ans * (pre ** j)) % 998244353
      pre = j
      
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d_list = list(map(int, input().split()))
divider = 998244353

if d_list[0] != 0:
  print(0)
else:
  d_sort = sorted(d_list)
  d = 1
  pre_c = 1
  cur_c = 0
  count = 1
  for i in range(1, n):
    if d_sort[i] == d:
      cur_c += 1
    elif d_sort[i] == d + 1:
      count *= pre_c ** cur_c
      count %= divider
      d += 1
      pre_c = cur_c
      cur_c = 0
    else:
      count = 0
      cur_c = 0
      break
  count *= pre_c ** cur_c
  count %= divider
  print(count)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
D = list(map(int,input().split()))
D = sorted(D)
c = collections.Counter(D)
c = c.most_common()
c.sort(key=lambda x:x[0])
s = 1
key =0
for i in range(len(c)):
  if c[i][0] == 0:
    key += 1
  else:
    if i == 0:
      pass
    else:
      s *= c[i-1][1]**c[i][1]
if len(c) != c[-1][0]+1:
  key = 0
if key == 1:
  print(s)
else:
  print(0)

Submission status: Wrong Answer

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

ans=1
for i in range(l):
  if i==0:
    if D[i]!=1:
      print(0)
      exit()
  else:
    if D[i]==0:
      print(0)
      exit()
    else:
      ans=(ans*((D[i-1]**D[i])%mod))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

input = raw_input
range = xrange
M = 998244353

def main():
    N = int(input())
    Ds = list(map(int, input().split(" ")))
    counter = collections.Counter(Ds)
    depths = counter.keys()
    
    min_depth = min(depths)
    max_depth = max(depths)

    if min_depth != 0:
        #print("test1")
        return 0
    elif counter[0] != 1:
        return 0
    
    if len(depths) != max_depth + 1:
        #print("test2")
        return 0

    out = 1
    for depth in range(1, max_depth+1):
        num = counter[depth]
        if depth >= 2:
            for i in range(num):
                out = out * before_num
                out = out % M
        before_num = num

    return out

out = main()
print(out)

Submission status: Wrong Answer

Solution code:
import collections
import sys


def solve():
    input = sys.stdin.readline
    mod = 998244353
    n = int(input().rstrip('\n'))
    d = list(map(int, input().rstrip('\n').split()))
    mn = 0
    if d[0] == 0:
        dic = collections.defaultdict(list)
        for i in range(n):
            dic[d[i]] += [i+1]
            mn = max(mn, d[i])
        ln = 1
        t = 1
        for i in range(1, mn+1):
            if len(dic[i]) != 0:
                t *= ln ** len(dic[i])
                t %= mod
                ln = len(dic[i])
            else:
                print(0)
                exit()
        print(t)
    else:
        print(0)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

if n == 1:
  print(1)
  
count = 1
for i in range(n-1):
  x = d[i+1]
  if x == 0:
    print(0)
    exit()
  if x == 1:
    continue
#  print(x, len([y for y in d if y == x - 1]))
  count = count * len([y for y in d if y == x - 1])

print(count)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def solve(N,D):
    if D[0] != 0: # ありえない
        return 0

    nums = Counter(D)
    nums = sorted(nums.items())
    ans = 1
    for i in range(len(nums)-1):
        ans *= nums[i][1]**nums[i+1][1]
        ans %= 998244353
    return ans

def main():
    N = int(input())
    D = list(map(int, input().split()))
    
    print(solve(N,D))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
#print(n,d)
cnt = collections.Counter(d)

ans = 1
for i in range(len(dict(cnt))):
  val = cnt[i]
  if val != 1:
    ans *= math.factorial(val)
    
ans *= cnt[1]
print(ans%MOD)

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)
else:
  idx = np.hstack([np.where(np.diff(D) == 1)[0], N])
  num = np.diff(idx)
  print(num)
#  out = 1
#  last = list(D).count(1)
#  for i in np.arange(2, max_depth+1):
#    now = list(D).count(i)
#    out *= np.power(last, now)
#    last = now
#  print(out % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def resolve():
    n = int(input())
    d = list(map(int, input().split()))
    c = Counter(d)
    m = max(c)
    ans = 1
    if d[0] != 0 or c[0] != 1:
        print(0)
        return
    for i in range(1, m + 1):
        if not i in c:
            print(0)
            return
        ans *= c[i - 1] ** c[i]
    print(ans)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
from itertools import dropwhile

n = int(input())
D = list(map(int, input().split()))
DIV = 998244353

dist = [0]*n

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

dist.reverse()
ddist = list(dropwhile(lambda x: x == 0, dist))
ddist.reverse()

ans = 1
for i in range(len(ddist) - 1):
    ans *= ddist[i] ** ddist[i+1]

if ddist[0] != 1:
    ans = 0
print(ans%DIV)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
a=[int(i) for i in input().split()]
c=Counter(a)
ans=1
if c[0]!=1:
    print(0)
    quit()

for i in range(n-1):
    ans *= (c[i]**c[i+1])%998244353
    ans %= 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = list(map(int, input().split()))
from collections import Counter
dic = Counter(D)
max_D = max(D)

num = 1
import sys
if D[0] != 0:
  print(0)
  sys.exit()
else:
  for i in range(1, max_D + 1):
    num *= (dic[i-1]) ** dic[i]
print(num)

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = d[0]
max_d = d[-1]
mod = 998244353

if min_d == max_d or d[0] == d[1]:
    print(0)
    sys.exit()
count = [1 for _ in range(max_d-min_d+1)]
num = min_d
counter = 0
for i in range(n):
    if d[i] == num:
        counter += 1
    else:
        if d[i] == num+1:
            count[num-min_d] = counter
            counter = 1
            num += 1
        else:
            print(0)
            sys.exit()
ans = count[1]
for i in range(1,max_d-min_d):
    n = count[i]-1
    m = count[i+1]
    ans *= (math.factorial(n+m)//(math.factorial(n)*math.factorial(m)))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

d = [int(i) for i in input().split()]

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

del d[0]

d.sort()

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

ans = 0
li = []
tmp = d[0]
cnt = 1
#print(d,len(d))

for i in range(len(d)-1):
    #print(i)
    if tmp == d[i+1]:
        cnt += 1
    else:
        li.append(cnt)
        tmp += 1
        if i+1 == len(d)-1:
            cnt = 1
            if d[i+1] != tmp:
                print(0)
                exit()
            break
        else:
            if d[i+1] != tmp:
                print(0)
                exit()
        cnt = 1

li.append(cnt)

ans = 1

for i in range(len(li)-1):
    ans = ans * li[i] ** li[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=sorted(list(map(int,input().split())))
if d[0]!=0:
    print(0)
else:
    c=Counter(d)
    c_v=list(c.keys())
    ans=1
    x=1
    while x<=max(c_v):
        ans*=c[x-1]**c[x]
        ans%=998244353
        x+=1
    print(ans)

Submission status: Wrong Answer

Solution code:
n= int(input())

dlist = list(map(int,input().split()))
lendlist = len(dlist)
ans = -1
dictdist = {}

for i in range(100001):
    dictdist[i] = 0

for i in range(lendlist):
    if i==0:
        if dlist[i]!=0:
            ans = 0
            
    elif i!=0:
        if dlist[i]==0:
            ans = 0
        else:
            dictdist[dlist[i]] += 1
                
if ans != 0:
    temp = 1
    for k,v in dictdist.items():
        temp *= k**v
        temp %= 998244353
    ans = temp
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys


def answerA():
    input = sys.stdin.readline
    N = int(input())

    print((N-1) // 2)


def answer():
    input = sys.stdin.readline
    N = int(input())
    distances = list(map(int, input().split()))

    maximum = max(distances)
    counts = []

    for d in range(1, maximum + 1):
        counts.append(distances.count(d))

    result = 1
    mod = 998244353

    if distances[0] != 0:
        result = 0
    elif 0 in counts:
        result = 0
    elif 0 in distances[1:]:
        result = 0
    else:
        for i, count in enumerate(counts):
            result *= counts[i-1]**count % mod

    print(result)


if __name__ == '__main__':
    answer()

Submission status: Wrong Answer

Solution code:
import sys


n = int(input())
d = list(int(x) for x in input().split())

if d[0] != 0:
    print(0)
    sys.exit()
d.sort()
ans = 1
key = 1
value = 1
for i in range(1, n):
    if i == 1 and d[i] != 1:
        print(0)
        sys.exit()
    else:
        pass
    if d[i] == d[i-1]:
        key += 1
    else:
        if d[i] == d[i-1] + 1:
            if d[i-1] == 1:
                value = key
                key = 1
            else:
                ans *= pow(value, key)%998244353
                value = key
                key = 1
        else:
            print(0)
            sys.exit()
ans *= pow(value, key)%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
def f_b():
    n, *d = map(int, open(0).read().split())
    c = [0]*(max(d)+1)
    for i in range(n):
        c[d[i]] += 1

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

    a = 0 if c[0]>1 else a
    print(a%998244353)

if __name__ == "__main__":
    f_b()

Submission status: Wrong Answer

Solution code:
mod=998244353

N=int(input())
L=[0 for i in range(N)]
D=list(map(int,input().split()))
#print(D)
for i in range(N):
    L[D[i]]+=1
#print(L)

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

ans=1
cnt=1
for i in range(1,N):
    ans*=pow(L[i-1],L[i],mod)
    cnt+=L[i]
    #print(ans,cnt)
    if cnt==N:
        break
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
c=0
a = list(map(int,input().split()))
a.sort()
mem = {}
mem['-1']=1
count = 1
for v in a:
    need = v-1
    if str(need) in mem:
        count *= mem.get(str(need))
        count %=mod
    else:
        count = 0
        break
    if str(v) in mem:
        mem[str(v)] = mem.get(str(v))+1
    else:
        mem[str(v)] = 1
if '0' in mem and mem.get('0')>1:
    print(0)
else:
    print(count%mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dict = defaultdict(int)
mod = 998244353
N = int(input())
D = [int(x) for x in input().split()]
dep = max(D)
for d in D:
    dict[d]+=1

if(dict[0]!=1):
    ans = 0
else:
    ans = 1
    for de in range(1,dep+1):
        ans *= dict[de-1]**dict[de]
        ans %= mod
print(ans)

Submission status: Wrong Answer

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

mod=998244353
if D[0]!=0:
  print(0)
else:
  ans=1
  for i in range(2,n):
    if D.count(i)==0:
      print(0)
      exit()
    ans*=(D.count(i-1)**D.count(i))%mod
  print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
mx=d[-1]
count=[0]*(mx+1)
j=0
MOD=998244353
if d[0]!=0:
    print(0)
    sys.exit()
count[0]=1
j=1
for i in range(1,n):
    if d[i]==j:
        count[j]+=1
    elif d[i]==j+1 and count[j]>0:
        j+=1
        count[j]+=1
    else:
        print(0)
        sys.exit()
c=1
#print(d,count)
for i in range(1,mx+1):
    c*=pow(count[i-1],count[i],MOD)
    c%=MOD
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(x) for x in input().split(' ')]

m = {}
for item in d:
    if item in m:
        m[item] += 1
    else:
        m[item] = 1

prev = 1
if 0 in m:
    s = 1
    for i in range(10 ** 5):
        if not i in m:
            break
        v = m[i]

        s *= (prev ** v)
        prev = v
else:
    s = 0

print(s % 998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
Dn = list(map(int,input().split(' ')))
Dn.sort()
previous_num = 0
previous_cnt = 1
current_num = 0
sum_num = 1
flag = False
if Dn[0] == 0:
    for i in range(1,N):
        if Dn[i] == previous_num + 1:
            current_num += 1
        elif Dn[i] == previous_num + 2:
            if previous_num > 0:
                sum_num = sum_num * (previous_cnt**current_num)
            previous_cnt = current_num
            previous_num += 1
            current_num = 1
        else:
            flag = True
            break
        if i == N-1:
            if previous_num > 0:
                sum_num = sum_num * (previous_cnt**current_num)
    if flag:
        print(0)
    else:
        print(sum_num)
else:
    print(0)

Submission status: Wrong Answer

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

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

ans=1

a=[0]*(n+1)

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

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353

def beki(x, n):
  if n == 0:
    return 1
  if n % 2 == 0:
    return beki(x * x % MOD, n // 2)
  else:
    return x * beki(x, n - 1) % MOD


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

ans = 1
cnt = 1
precnt = 1
if D[0] != 0:
    ans = 0
if N > 1 and D[-1] == 0:
    ans = 0
    
for i in range(N-1):
    if D[i] == D[i+1]:
        cnt += 1
    elif D[i] + 1 != D[i+1]:
        ans = 0
        break
    else:
        ans *= beki(precnt, cnt)
        precnt = cnt
        cnt = 1
        if (i == N-1):
            break
else:
    ans *= beki(precnt, cnt)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, D):
    M = Mod(998244353)
    D.sort()
    if D[0] != 0:
        return 0
    C = Counter(D)
    ans = 1
    for i in range(1, max(D)+1):
        if C[i-1] == 0:
            return 0
        ans = M.mul(ans, M.pow(C[i-1], C[i]))
    return ans


def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def solve(N,D):
    if D[0] != 0: # ありえない
        return 0

    nums = Counter(D)
    nums = sorted(nums.items())
    ans = 1
    for i in range(len(nums)-1):
        ans *= nums[i][1]**nums[i+1][1]
    return ans

def main():
    N = int(input())
    D = list(map(int, input().split()))
    
    print(solve(N,D))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)

Submission status: Wrong Answer

Solution code:
def f_b():
    n, *d = map(int, open(0).read().split())
    c = [0]*(max(d)+1)
    for i in range(n):
        c[d[i]] += 1

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

    a = 0 if c[0]>1 else a
    print(a)

if __name__ == "__main__":
    f_b()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    D = [int(c) for c in input().split()]

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

    for i in range(1, N):
        if D[i] >= N or D[i] == 0:
            print(0)
            sys.exit()

    dist_nums = {}
    for i in range(N):
        if dist_nums.get(D[i]) is None:
            dist_nums[D[i]] = 1
        else:
            dist_nums[D[i]] += 1

    ans = 1
    num = 1   
    dist_nums = sorted(dist_nums.items(), key=lambda x: x[0]) # [(0, 1), (1, 2), (2, 1)]
    for i in range(1, len(dist_nums)):
        if dist_nums[i][0] == i:
            ans *= dist_nums[i - 1][1] ** dist_nums[i][1]
            num += dist_nums[i][1]
        else:
            break
    
    if num != N:
        print(0)
    else:
        print(ans)




    
    
    

    
    


if __name__ == '__main__':
    main()

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+1):
        if anslist[j]!=0 and anslist[j+1]!=0:
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
        elif anslist[j+1]==0:
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline

N = int(input().strip())
C = [0] * N
D = [int(x) for x in input().strip().split()]
maxD = max(D)
for d in D:
    C[d] += 1
ans = 1
c_ = 1
if D[0] != 0:
    ans = 0
else:
    for i, c in enumerate(C[1:], start=1):
        if i > maxD:
            break
        if c == 0:
            ans = 0
            break
        ans *= c_ ** c
        c_ = c

print(ans % 998244353)

Submission status: Wrong Answer

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

if c[0] != 1:
	print(0)
	exit()
flag = True
for i in range(N):
	if not flag and c[i] > 0:
		print(0)
		exit()
	if c[i] == 0:
		flag = False

if c[2] == 0:
	print(1)

ans = 1
for i in range(1, N):
	if c[i] == 0:
		print(ans)
		exit()
	t = (c[i-1] ** c[i]) % MOD
	ans = (ans * t) % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
s=[0]*n
m=998244353
for i in d:
    s[i]+=1
if s[0]==1:
    c=1
    a=1
    for i in range(1,n):
        if s[i]!=0:
            c+=s[i]
            a=(a*pow(s[i-1],s[i],m))%m
        else:
            break
    if c==n:
        print(a%m)
    else:
        print(0)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
MOD = 998244353  # type: int

def solve(N: int, D: "List[int]"):
    if D[0] != 0:
        print(0)
        return 

    D.sort()
    counter = Counter(D).items()

    answer = 1
    prev_node_count = 1

    for c in counter:
        answer*=prev_node_count**c[1]
        prev_node_count = c[1]
    
    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import collections
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

c = collections.Counter(D)
c = dict(c)

ans = 1
tmp = 1
for i in range(mD+1):
    if not(i in c.keys()):
        ans = 0
        break
    elif i == 0:
        if c[0] > 1:
            ans = 0
            break
    elif i == 1:
        tmp = c[i]
    else:
        ans = (ans * tmp**c[i])%MOD
        tmp = c[i]

print(ans)

Submission status: Wrong Answer

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

a = [0] * n
for i in range(n):
    a[d[i]] += 1

ans = 1
for i in range(n):
    if i == 0:
        if a[i] != 1:
            ans *= 0
    else:
        if a[i] > 0:
            if a[i-1] == 0:
                ans *= 0
            else:
                ans *= pow(a[i-1], a[i], MOD)
                ans %= MOD
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np


N = int(input())
D = np.array([int(d_) for d_ in input().split()])

D_list = np.array(list(set(D)))
if (np.min(D_list) != 0) | (np.max(D_list) != len(D_list) - 1) | (len(D[D == 0]) != 1):
    print(0)
else:
    ans = 1
    for d1, d2 in zip(D_list[:-1], D_list[1:]):
        ans *= len(D[D == d1])**len(D[D == d2])
    print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    SSSS = 998244353
    D = string_to_int(inputs[0])
    # {distance: numbers}
    nodes = {}
    for i, d in enumerate(D):
        i += 1
        if d not in nodes:
            nodes[d] = [i]
        else:
            nodes[d].append(i)

    if 0 not in nodes:
        return 0

    prev = -1
    prev_num = -1
    count = 0
    for d in sorted(nodes.keys()):
        if d == 0:
            if not (len(nodes[d]) == 1 and nodes[d][0] == 1):
                return 0
            count = 1
            prev_num = 1
            continue
        if abs(d - prev) == 1:
            return 0

        count *= prev_num ** len(nodes[d])
        prev_num = len(nodes[d])
    return count % SSSS


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Nov  9 20:46:00 2019

@author: ctiuser
"""
import sys

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

D.sort()
T = [0 for _ in range(N + 1)]

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

i = 0
ans = 1
if T[i] != 1:
    print(0)
    sys.exit()
pre = T[i]
i += 1
while T[i] != 0:
    ans *= pow(pre,T[i])
    ans %= mod
    pre = T[i]
    i += 1

while i < N:
    if T[i] > 0:
        print(0)
        sys.exit()
    i += 1

ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(d) for d in input().split()]

D.sort()
mod = 998244353

if D[0] == 0:
    if N == 1:
        ans = 1
    elif D[1] == 1:
        prev = 1
        cnt = 0
        num = 1
        ans = 1
        for i in range(1, N):
            if D[i] == num:
                cnt += 1
            elif num == 1:
                prev = cnt
                cnt = 1
                num += 1
            elif D[i] == num+1:
                ans *= prev**cnt
                ans %= mod
                prev = cnt
                cnt = 1
                num += 1
            else:
                ans = 0
                break
        ans *= prev**cnt
        ans %= mod
    else:
        ans = 0
else:
    ans = 0
    
print(ans)

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:
    l = [0 for i in range(n)]
    for i in range(n):
        l[d[i]] += 1
    flag = 0
 #   print(l)
    for i in range(2,n):
        if flag == 1 and l[i] != 0:
            ans = 0
            break
        else:
            if l[i] != 0:
                ans = ans * l[i-1]**l[i]
            elif l[i] == 0:
                flag = 1
    print(ans)
    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


m = I()
D = LI()
cnt = Counter(D)
ret = 1
for i in range(max(D) + 1):
    val = cnt[i]
    if not val:
        print(0)
        break
    else:
        if i == 0:
            continue
        elif i == 1:
            pre = val
        else:
            ret = pow(pre, val, mod) * ret % mod
            pre = val
else:
    print(ret)

Submission status: Wrong Answer

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

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

ans=1

a=[0]*(n+1)

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

for j in range(n):
  if j!=0 and a[j] == 0:
    for k in range(j+1,n):
      if a[k] != 0:
        print(0)
        exit()
    break
  else:
    ans*=(a[j]**a[j+1])

print(ans,a)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = [int(i) for i in input().split()]
mod = 998244353

def solve() :
    c = Counter(D)
            
    if c[0] != 1 :
        return 0
        
    ret = 1
    for i in range(1, max(c) + 1) :        
        ret = ret * pow(c[i-1], c[i], mod) % mod
    
    return ret
        
print(solve())