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:
def f():
    n = int(input())
    d = [int(s) for s in input().split()]
    d.sort()
    if d[0] != 0 or d[1] == 0:
        return 0
    count = [1]
    v = 1
    c = 0
    for i in range(1,n):
        if d[i] != v:
            if c == 0:
                return 0
            count.append(c)
            v += 1
            c = 1
        else:
            c += 1
    count.append(c)
    print(count)

    ans = 1
    last = 1
    for cur in count:
        ans *= (last**cur)%998244353
        last = cur
    return ans%998244353

print(f())

Submission status: Wrong Answer

Solution code:
from collections import Counter 
n = int(input())
d = list(map(int,input().split()))
c = Counter(d)
ans = 1
if c[0]==1:
  x = c[0]
  for a,b in c.items():
    y = b
    ans*=x**y
    x = b
else:
  ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [0]*n
for i in input().split():
  d[int(i)]+=1
if d[0]!=1:
  print(0)
else:
  mod = 998244353
  ans=1
  for i in range(n-2):
    ans*=((d[i]%mod)**(d[i+1]%mod))%mod
  print(ans%mod)

Submission status: Wrong Answer

Solution code:
valid = True
n = int(input())
ds = [int(i) for i in input().split()]
ds.sort()
count = []
c = 1
for i in range(len(ds)-1):
    if((i==0 and not ds[i]==0) or (not i==0 and ds[i]==0)):
        valid = False
        print(0)
        break
    if(ds[i]==ds[i+1]):
        c += 1
    elif(ds[i]==ds[i+1]-1):
        count.append(c)
        c = 1
    else:
        valid = False
        print(0)
        break
count.append(c)

s = 1
for i in range(len(count)-1):
    s *= count[i]**count[i+1]

if(valid):
    print(int(s)%998244353)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
    exit(0)
    
max_D = max(D)
    
c = [0] * (max_D+1)
for i in range(N):
    c[D[i]] += 1
   
ans = 1 
for i in range(max_D):
    ans *= c[i] ** c[i+1]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = []
ansflag = 0
ans = 1
for i in range(max(D)+1):
    temp = D.count(i)
    if temp == 0:
        ansflag = 1
        break
    else:
        D_.append(temp)
        if len(D_) > 1:
            ans *= D_[-2] ** D_[-1]
            ans % 998244353

if ansflag:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = list(map(int, input().split()))
d.sort()
tmp = d[n - 1]
ans = 1
if d[0] != 0:
    print(0)
else:
    c = collections.Counter(d)
    for i in range(2, n):
        if i in c.keys():
            ans *= i ** c[i]
            ans %= 998244353
            if i == tmp:
                break
        else:
            print(0)
            exit()
    if ans == 0 and (1 in c.keys()):
        ans += c[1] - 1
    print(ans)

Submission status: Wrong Answer

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

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

c = Counter(D)
if c[0] != 1:
    print(0)
    exit(0)
d = max(c)
ans = 1
base = 1
for i in range(1, d+1):
    if c[i] == 0:
        print(0)
        exit(0)
    ans *= (base ** c[i])
    ans = ans % MOD
    base = c[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

set_d = set(d)
list_d = list(set_d)
dict_d = Counter(d)

ans = 1
cnt = 1
temp = 0
check = 1

for i in list_d:
    if i == 0:
        continue
    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = ans * check**cnt
    check = cnt
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = [int(i) for i in input().split()]
ans = 0
if d[0] == 0:
    s = collections.Counter(d)
    if d.count(0) == 1:
        ss = sorted(list(s.items()))
        sss = sorted(set(d))
        for i in range(len(sss)):
            if sss[i] != i:
                break
        else:
            ans = 1
            for (i,j) in ss:
                if i != 0:
                    ans *= i**j
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys
from collections import Counter

N=input()
D=map(int, sys.stdin.readline().split())
max_D=max(D)

C=Counter(D)

mod=998244353
if D[0]!=0:
    print 0
    quit()
else:
    ans=1
    for i in range(2,max_D+1):
        ans*=pow(C[i-1],C[i],mod)
        ans%=mod

print ans%mod

Submission status: Wrong Answer

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

_n = int(input())
_dlist = list(map(int, input().split()))


def chker(n, dlist):
    if dlist[0] != 0:
        print(0)
        return

    ds = dlist[1:]
    ds.sort()
    cntlist = [0] * n
    if ds[0] == 1:
        print(0)
        return

    cntlist[ds[0]] = 1
    for i in range(1, n - 1):
        if ds[i] <= ds[i - 1] + 1:
            cntlist[ds[i]] += 1
        else:
            print(0)
            return

    ans = 1
    for i in range(2, n):
        ans = (ans * cntlist[i - 1] ** cntlist[i]) % 998244353

    print(ans)


chker(_n, _dlist)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
N = int(input())
D_list = list(map(int, input().split()))
P = 998244353
n = 1
c = Counter(D_list)
if c[0] == 0:
    print(0)
else:
    pre = 1
    for i in range(1, max(D_list) + 1):
        if c[i] == 0:
            print(0)
            sys.exit()
        n *= pre ** c[i]
        n = n % P
        pre = c[i]
    print(n)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

mod = 998244353
n = int(input())
d = list(map(int, input().split()))
c = collections.Counter(d)
ans = 1

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

try:
    for i in range(1, len(c)-1):
        ans = (ans*c[i]**c[i+1]) % mod
except KeyError:
    print(0)
    sys.exit()

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np


def q1(n):
    return (n - 1) // 2


def q2(n, D):
    counts = [np.sum(D == level) for level in range(n)]
    if counts[0] == 0:
        return 0
    tmp = 1
    for i in range(2, n):
        if counts[i] == 0:
            return tmp
        tmp *= counts[i - 1] ** counts[i]
    return tmp


if __name__ == '__main__':
    MAXINT = 998244353

    # A 問題
    # n = int(input())
    # print(q1(n))

    # B 問題
    n = int(input())
    D = np.asarray(list(map(int, input().split())))
    # n = 4
    # D = np.array([0, 1, 1, 2])
    # D = np.array([1, 1, 1, 1])
    # n = 7
    # D = np.array([0, 3, 2, 1, 2, 2, 1])
    print(q2(n, D) % MAXINT)

Submission status: Wrong Answer

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

ans = 1
ans_li = [0 for i in range(n)]

li.sort()
count = 0
for i in range(n):
    ans_li[li[i]] += 1

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

c = collections.Counter(d)
if c[0] != 1:
    print('0')
else:
    ans = 1
    v = list(c.values())
    for i in range(1, len(v)):
        ans *= v[i-1]**v[i]
    print(ans % MOD)

Submission status: Wrong Answer

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

d.sort()

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

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


mini = d[0]
maxi = d[-1]
num = 1
cnt = 0
lst = [1]
for i in d[1:]:
    if i == num:
        cnt += 1
    elif i == num+1:
        lst.append(cnt)
        num = i
        cnt = 1
    else:
        print(0)
        exit()

lst.append(cnt)

ans = 1
for i in range(1, len(lst)-1):
    ans = (ans * lst[i]**lst[i+1]) % 998244353

print(ans)

Submission status: Wrong Answer

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

count = Counter(dli)
# 木である条件
for ind, key in enumerate(count.keys()):
    if ind != key:
        print(0)
        exit()

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

tmp = []
for ind in range(len(sort)-1):
    mae = sort[ind][1]
    next = sort[ind+1][1]

    tmp.append(int(mae**next))

total = 1
for t in tmp:
    total *= t
print(total%mod)

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()
    if l[0] >= 2:
        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%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=input()
S=input()
print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

#lines = stdin.readlines()
def rint():
    return map(int, sys.stdin.readline().split())

def input():
    return sys.stdin.readline().rstrip('\n')

def oint():
    return int(input())

N = oint()

d = list(rint())

d.sort()
print(d)

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

n = 1
c = 0
cprev = 1
ans = 1
for i in range(1, N):
    if d[i] == n:
        c+=1
    elif d[i] != n+1:
        print(0)
    else:
        ans = (ans* pow(cprev, c, 998244353))%998244353
        n += 1
        cprev = c
        c = 1

ans = (ans* pow(cprev, c, 998244353))%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
a = [int(i) for i in input().split()]
a.sort()

c = collections.Counter(a)

ans = 1
now = 1
if a[0] != 0 or a[1]==0:
    print(0)
else:
    last = a[-1]
    for i in range(1,last+1):
        cnt = c[i]
        if cnt==0:
            ans = 0
            break
        else:
            ans *= ((now**cnt)%998244353)
            ans %= 998244353
            now = cnt
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    exit()
import collections
cnt = collections.Counter(D[1:])
if 0 in cnt:
    print(0)
    exit()
maxs = 998244353
res = 1
flag = True
scnt = sorted(cnt.items(), key=lambda x: x[0])
if scnt[0][0] != 1:
    print(0)
else:
    for i in range(1, len(scnt)):
        if scnt[i][0] != scnt[i-1][0] + 1:
            flag = False
            break
        # pre = res
        res = (res * (scnt[i-1][1] ** scnt[i][1])) % maxs
        # print(res)
    print(res) if flag else 0

Submission status: Wrong Answer

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

N = input1[0]
D = input2

counter = []

for num in range(max(D)+1):
  counter.append(D.count(num))

ans = 1

if counter[0] != 1:
  ans = 0
else:
  for i in range(len(counter)-1):
    ans *= counter[i]**counter[i+1]

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if D[0]!=0:
    print(0)
else:
    count_list = [ np.where(D==x,1,0).sum() for x in range(1,D.max()+1)]

    ans = 1
    for x in range(len(count_list)-1):
        ans = ans * (count_list[x]**count_list[x+1])
    print(ans)

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]

if N == 1:
    if D[0] == 0:
        print(1)
    else:
        print(0)
elif N < 3:
    print(D[100])
else:
    print(ans)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
    exit(0)
    
max_D = max(D)
    
c = [0] * (max_D+1)
for i in range(N):
    c[D[i]] += 1
   
ans = 1 
for i in range(max_D):
    ans *= c[i] ** c[i+1]
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if len(set(D))==1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(0,max(D)+1):
        #print(cnt[i],tmp)
        c = tmp**cnt[i]
        ans *= c
        tmp = cnt[i]
    print(ans % mod)

Submission status: Wrong Answer

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

output = 1
if a[0] != 0:
    print(0)
else:
    for i in range(1, n):
        if a[i] != 0:
            output *= a[i]
    print(output)

Submission status: Wrong Answer

Solution code:

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 998244353
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
DD = inpl()
cnts = [0]*N
m = -1
for d in DD:
    cnts[d] += 1
    m = max(d,m)

if cnts[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(1,m+1):
        if cnts[i] == 0:
            print(0)
            sys.exit()
        ans *= pow(cnts[i-1],cnts[i],mod)
        ans %= mod
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- Coding: utf-8 -*-

import sys
from collections import Counter


input = sys.stdin.readline
MOD = 998244353


def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    c = Counter(D)
    k = list(c.keys())
    k.sort()
    if D[0] != 0 or c[0] != 1:
        print(0)
        sys.exit(0)

    ans = 1
    for i, n in enumerate(k):
        if i != n:
            print(0)
            sys.exit(0)
        if n == 0:
            continue
        ans *= c[n-1]**c[n]

    print(ans)


if __name__ == '__main__':
    main()

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.values())
    c_k=list(c.keys())
    ans=1
    check=1
    for i in range(1,len(c_v)):
        if c_k[i]!=check:
            print(0)
            exit()
        check+=1
        ans*=c_v[i-1]**c_v[i]
        ans%=998244353
    print(ans)

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])%mod
        ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
CONST_DIVSOR = 998244353
N = int(input())
Ds = list(map(int, input().strip().split()))

total = 0
cnt = 0
prenumi = 0
for i in range(N):
    if i == 0:
        if Ds.count(i) == 1:
            total = 1
            prenumi = 1
            cnt = 1
        else:
            break
    else:
        numi = Ds.count(i)
        if numi != 0:
            total = total * (prenumi ** numi)
            prenumi = numi
            cnt += numi
        else:
            total = 0
            break
    # print(i,total,prenumi,cnt)
    if cnt >= N:
        break

print(total % CONST_DIVSOR)

Submission status: Wrong Answer

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

a = collections.Counter(num_list)
maxim = sorted(num_list)[-1]

flag = 0
ans = 1
for i in range(1,maxim+1):
    if a[i-1] == 0:
        flag = 1
        break
    if a[i-1] != 1 and a[i]!=1:
        ans = ans * (a[i]*(a[i-1] + (a[i]-1)))
    else:
        ans = ans * (a[i])
if flag == 1:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=list(map(int,input().split()))

temp=[0]*(max(l)+1)
for item in l:
    temp[item]+=1

for i in range(len(temp)-1):
    if temp[i]==0:
        print(0)
        exit()
    

ans=1
for i in range(2,len(temp)):
    #print(ans)
    ans=ans*temp[i-1]**temp[i]
print(ans)

Submission status: Wrong Answer

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

D.sort()
E=[]

a=0
b=0
while True:
   b=D.count(a)
   
   if(b==0):
       break
   E.append(b)
   a+=1
f=sum(E)
if(N!=int(sum(E))):
    print(0)
else:
    c=1
    for i in E:
       c*=i
    print(c)

Submission status: Wrong Answer

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

ans=1

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

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
A = list(map(int,input().split()))
D = [1 for _ in range(max(A)+1)]
if N == 1:
    if A[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

D[1] = A.count(1)
ans = 1
if A[0] > 0 or D[0] > 1:
    print(0)
else:
    for i in range(2,max(A)+1):
        D[i] = A.count(i)
        ans *= (D[i-1]**D[i])%mod
    print(ans)

Submission status: Wrong Answer

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

X = 998244353

l_max = max(D)

def f():
    if D[0] != 0:
        print(0)
        return
    L = [0] * (l_max+1)
    for d in D:
        L[d] += 1 

    ans = 1
    L = [1] + L
    #print(L)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod=998244353
N=int(input())
D=list(map(int,input().split()))
if D[0]==-1:
  print(0)
else:
  tmp=Counter(D)
  ans=1
  for i in tmp.keys():
    if i==0:
      continue
    ans*=tmp[i-1]**tmp[i]
    ans%=mod
  print(ans)

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 += c[i][0]
  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%998244353)
else:
  print(0)

Submission status: Wrong Answer

Solution code:
INF = 998244353

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

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

if p[0]!=1:
    print(0)
    exit()
ans = 1
j = 1
for i in range(1,n+10):
    if p[i]==0:
        break

    ans = (ans*(p[i-1]**p[i]))%INF
    j +=p[i]
if j!=n:
    print(0)
    exit()
print(ans)

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

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

        s *= (prev ** v) % 998244353
        prev = v
    
    if visited != n:
        s = 0
else:
    s = 0

print(s % 998244353)

Submission status: Wrong Answer

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

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

length = 1
length_list = []
count = 0
for i in range(len(D)):
    if length == D[i]:
        count += 1
    else:
        if length+1 != D[i]:
            print(0)
            exit()
        else:
            length += 1
            length_list.append(count)
            count = 1
length_list.append(count)
        
ans = 1
for i in range(len(length_list)-1):
    ans *= length_list[i] ** length_list[i+1]


print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
else:
  for i in range(1,n-1):
    if d[i] == d[i+1]:
      cnt += 1
    else:
      cnt += 1
      li.append(cnt)
      cnt = 0
    if i == n-2:
      if d[n-2] == d[n-1]:
        cnt += 1
        li.append(cnt)
      else:
        li.append(1)
  for i in range(len(li)-1):
    ans = (ans*((li[i]**li[i+1])%998244353)%998244353)
  print(ans)

Submission status: Wrong Answer

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

if n==1:
	if d[0]==0:
		print(1)
		exit()
	else:
		print(0)
		exit()
elif n==2:
	if d==[0,1]:
		print(1)
		exit()
	else:
		print(0)
		exit()
if d[0]!=0 or d[1]!=1:
	print(0)
	exit()
for i in range(n-1):
	if d[i+1]>d[i]+1:
		print(0)
		exit()
p=[]
cnt=1
for i in range(1,n-1):
	if d[i]==d[i+1]:
		cnt+=1
	elif d[i+1]==d[i]+1:
		p.append(cnt)
		cnt=1
p.append(cnt)
ans=1
for i in range(len(p)-1):
	ans*=p[i]**p[i+1]
	ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
li = list(map(int, input().split()))
a = 1
if li.count(0) == 0:
  print(0)
elif li.count(0) == 1:
  for i in range(1,max(li)):
    a *= (li.count(i)**li.count(i+1))
  print(a)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
a=sorted([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):
    if a[i+1]-a[i]>1:
        print(0)
        quit()

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

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
mod = 998244353
n=int(input())
d=[int(i) for i in input().split()]
ans=[0]*n
for i in d:
    ans[i]+=1
f=mod
for i in ans:
    if f==0 and i>0:
        print(0)
        exit()
    f=min(f,i)
if d.count(0)!=1:
    print(0)
    exit()
cnt=1
for i in range(1,n):
    if ans[i]==0:
        break
    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod

print(cnt%mod)

Submission status: Wrong Answer

Solution code:
valid = True
n = int(input())
ds = [int(i) for i in input().split()]
ds.sort()
count = []
c = 1
for i in range(len(ds)-1):
    if((i==0 and not ds[i]==0) or (not i==0 and ds[i]==0)):
        valid = False
        print(0)
        break
    if(ds[i]==ds[i+1]):
        c += 1
    elif(ds[i]==ds[i+1]-1):
        count.append(c)
        c = 1
    else:
        valid = False
        print(0)
        break
count.append(c)

s = 1
for i in range(len(count)-1):
    s *= count[i]**count[i+1]

if(valid):
    print(int(s))

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
    m = 998244353
    for i in range(1, len(c)):
        a = a*c[i-1]**c[i]%m

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

if __name__ == "__main__":
    f_b()

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

mem = [-1 for i in range(n+1)]
def countd(y):
  if mem[y] == -1:
    mem[y] = len([y for y in d if y == x - 1])
  return mem[y]

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

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

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
tmp = input().split()
L = []
LL = [0 for i in range(pow(10,5)+1)]
maximum = 0
for i in range(n):
  L.append(int(tmp[i]))
  LL[L[i]] += 1
  if L[i] > maximum:
    maximum = L[i]
  
out = 1
for i in range(maximum+1):
  out *= pow(i+1, LL[i+1])

if L[0] != 0 or LL[0] != 1:
  out = 0
print(out % 998244353)

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().strip()


def main():
    d = [input() for _ in range(2)]
    n = d[0]
    d = list(map(int, d[1].split(' ')))
    d.sort()
    mod = 998244353
    if d.count(0) != 1:
        print(0)
    else:
        count = 1
        for i in d[1:]:
            count = ((count % mod) * (i % mod)) % mod
        print(count)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
dd = list(map(int, input().split()))
dd.sort()
ans = 1
ls = []

for i in range(n):
    if dd[i] > i:
        print(0)
        exit()
    else:
        cnt = dd[:i].count(max(dd[:i+1])-1)
        ls.append(cnt)


for i in ls:
    if i > 0:
        ans *= i

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        D = list(map(int, input().split()))

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

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

        dis = {0: 1}
        for d in D:
            if d - 1 not in dis.keys():
                print(0)
                exit()
            else:
                if d not in dis.keys():
                    dis[d] = 1
                else:
                    dis[d] += 1

        ans = 1
        for k, v in dis.items():
            if k > 1:
                ans *= (dis[k - 1]) ** v
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
d = list(map(int, input().split()))
d.sort()
tmp = d[n - 1]
ans = 1
if d[0] != 0:
    print(0)
else:
    c = collections.Counter(d)
    for i in range(2, n):
        if i in c.keys():
            ans *= i ** c[i] % 998244353
            if i == tmp:
                break
        else:
            print(0)
            exit()
    if ans == 0 and (1 in c.keys()):
        ans += c[1] - 1
    print(ans)

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 d[0] == d[1] or d[0] != 0:
    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())
ds = [int(d) for d in input().split(" ")]

d_cnt = {}
d_max = max(ds)

for i in range(d_max + 1):
    d_cnt[i] = 0

for i in ds:
    d_cnt[i] += 1

cnt = 1
for i in range(1, d_max + 1):
    cnt *= d_cnt[i - 1] ** d_cnt[i]

print(cnt)

Submission status: Wrong Answer

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

_n = int(input())
_dlist = list(map(int, input().split()))


def chker(n, dlist):
    if dlist[0] != 0:
        print(0)
        return

    ds = dlist[1:]
    ds.sort()
    cntlist = [0] * n
    if ds[0] > 1:
        print(0)
        return

    cntlist[ds[0]] = 1
    for i in range(1, n - 1):
        if ds[i] <= ds[i - 1] + 1:
            cntlist[ds[i]] += 1
        else:
            print(0)
            return

    ans = 1
    for i in range(2, n):
        ans = (ans * cntlist[i - 1] ** cntlist[i]) % 998244353

    print(ans)


chker(_n, _dlist)