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())
vertex_list = list(map(int, input().split()))
if vertex_list[0] != 0:
    print(0)
else:
    maxx = max(vertex_list)
    list = []
    mark = 0
    ans = 1
    for i in range(1,maxx+1):
        if i not in vertex_list:
            mark = -1
        ans *= (i) ** vertex_list.count(i)
    if mark == -1:
        print(0)
    else:
        print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)
keys = sorted(c.keys())
max = keys[len(keys)-1]
ok = True
if c[0] != 1:
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = True
            break
        count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*pow(c[i],c[i+1])
        ans =  ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
  
N = int(input())
D = list(map(int, input().split()))
df = D[0]
D.sort()
ans = 1
e = 0
f = 0 
  
l = collections.Counter(D)  
 
for i in range(N):
  if l[i] != 0:
      ans *= l[i] ** l[i+1]
 
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1

for i in range(N):
  if i == 0:
    pass
  else:
    if D[i] == 0:
      f = 1      

if D.count(0) != 1 or e == 1 or f==1:
  print(0)
elif N == 1:
  print(1)
else:
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    ans = 1
    for i in range(len(C) - 1):
        if C[i] == 0:
            ans = 0
            break
        ans *= C[i] ** C[i+1]
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
ans=1
error=0
if num[0]!=1:
    error=1
for i in range(1, max(d)+1):
    ans*=num[i-1]**num[i]
    if num[i]==0:
        error=1
if error==0:
    print(ans%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
#from math import factorial
n = int(input())

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

D.sort()
#print(D)
num = 1
m = 0
flag = 1
mb = 0
for i in D:
    if i == 0:
        mb += 1
    else:
        break
#print(mb)
S = mb

for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        if flag == 0:
            pass
        a = mb ** m
        S *= a
        mb = m
        m = 1
        num += 1

a = mb ** m
S *= a
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

Solution code:
n = int(input())
d = tuple(int(i) for i in input().split(' '))

if not 0 in d:
    print(0)
    exit()
    

counts = [0] * n
for dd in d:
    counts[dd] += 1;
    
result = 1;
for i in range(1, n-1):
    result *= pow(counts[i], counts[i+1])
    
print(result)

Submission status: Wrong Answer

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


def main():
    from collections import defaultdict
    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
    dc = defaultdict(int)
    for i in d[1:]:
        dc[i] += 1
    for i in range(1, d[-1]):
        count = ((count % mod) * ((dc[i]**dc[i+1]) % mod)) % mod
    print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

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

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

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

c=Counter(d)
d_max=max(d)
ans=1
flag=True

if d[0]!=0:
    print(0)
elif d.count(0)>1:
    print(0)
elif d_max==1:
    print(d.count(1))
else:
    for i in range(2, d_max+1):
        if c[i-1]==0:
            flag=False
        else:
            ans=ans*(c[i-1]**c[i])

    print(ans%998244353 if flag else 0)

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 N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)

else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        c = (tmp**cnt[i]) % mod
        ans *= c
        tmp = cnt[i]
        ans = ans % mod
    print(ans % mod)

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]) % 998244353)*ans) % 998244353
    p=c[i]
    for i in range(c[i+1]):
        ans = ((ans%998244353) * (p%998244353))%998244353


print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections


n = int(input())

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


count_dict = collections.Counter(d)
result = 1
for i in range(1,max(d)+1):
    prenum = count_dict[i-1]
    nownum = count_dict[i]
    tem = prenum**nownum % 998244353
    result *= tem
    #result %= 998244353
 
print(result)

Submission status: Wrong Answer

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

ans = 1

Dict = {}

for i in range(N):
    if i == 0:
        if D[i] != 0:
            ans = 0
            break
    else:
        if D[i] in Dict:
            Dict[D[i]] += 1
        else:
            Dict[D[i]] = 1

if len(Dict) != 0:

    for j in sorted(Dict.keys()):
        ans *= (j)**Dict[j]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
d = list(map(int, input().split()))
m = {}
ans = 1

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

for i in range(n):
    num = d[i]
    if num in m:
        m[num] += 1
    else:
        m[num] = 1

#print(m)
#print(max(m))

#for i in range(1, max(m)+1):
for i in range(0, max(m)):
    if i not in m or i + 1 not in m:
        print(0)
        sys.exit()
    prevCnt = m[i]
    curCnt = m[i+1]
    # prevCnt = m[i] % 998244353
    #curCnt = m[i+1] % 998244353
    ans *= prevCnt ** curCnt
    #ans *= (prevCnt ** curCnt) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

if min(Ds)!=0 or Ds.count(0)!=1:
    print(0)
else:
    Ans=[0]*(max(Ds)+1)
    Ans[0]=1
    Count=[0]*(max(Ds)+1)
    Count[0]=1
    for i in range(1, max(Ds)+1):
        Count[i]=Ds.count(i)
        Ans[i]=(Count[i-1]**Count[i])%998244353

    print(np.prod(Ans))

Submission status: Wrong Answer

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

f=True
d={}
a=0
for i in range(N):
	if D[i] not in d:
		if D[i]==a:
			d[D[i]]=1
			a=D[i]+1
		else:
			f=False
			break
	else:
		d[D[i]] += 1

if not(f):
	print(0)
elif d[0]>1:
		print(0)
else:
	ans=1
	d = list(d.values())
	for i in range(1, len(d))[::-1]:
		ans *= (d[i-1]**d[i])
		ans %= 998244353
	print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
d = list( map(int, input().split()) )
MOD = 998244353

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0
    

    res = 1
    for i in range(2, iter+1):
        res *= (c[i-1]**c[i])%MOD
        res %= MOD
    return res

res = count(c, max(d))
print(res)

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)
keys = sorted(c.keys())
max = keys[len(keys)-1]
ok = True
if c[0] != 1:
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = True
            break
            count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*pow(c[i],c[i+1])
        ans =  ans % 998244353
    print(ans)

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)
    Anslist=anslist[::-1]
    flag=False
    judge=True
    for j in range(n):
        if Anslist[j]>0 and not flag:
            flag=True
        if Anslist[j]>0 and flag:
            judge=False
    if judge:
        print(ans%(998244353))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def count_tree(d):
    n = max(int(i) for i in d)
    cnt = 1
    if d[0] != "0":
        return 0
    dd = Counter(d)
    if dd["0"] != 1:
        return 0
    for i in range(1, n):
        if dd[str(i + 1)] > 0 and dd[str(i)] < 1:
            return 0
        else:
            cnt *= pow(dd[str(i)], dd[str(i + 1)], 998244353)
    return cnt

input()
print(count_tree(input().split()))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
if D[0] != 0:
    print(0)
    sys.exit()
E = D[1:]
d = dict(Counter(E))
sum_=1
temp=1
max_n=max(d.keys())
if len(d) ==1:
    if list(d.keys()) == [0]:
        print(0)
        sys.exit()
for i in range(1,max_n+1):
    try:
        add = (temp ** d[i]) % lim
        sum_ = (sum_ * add) % lim
        temp = d[i]
    except:
        print(0)
        sys.exit()
print(sum_)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

answer = 1
if l[0] != (0, 1):
    answer = 0
else:
    for i in range(M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer % 998244353)

Submission status: Wrong Answer

Solution code:
#from math import factorial
n = int(input())

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

D.sort()
#print(D)
num = 1
m = 0
flag = 1
mb = 0
for i in D:
    if i == 0:
        mb += 1
    else:
        break
#print(mb)
S = mb

for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        if flag == 0:
            pass
        a = mb ** m
        S *= a
        mb = m
        m = 1
        num += 1
        while num not in D:
            num += 1
            if max(D) < num:
                break
#            print(num)
a = mb ** m
S *= a
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

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

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i], MOD)

    print(count)




    

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):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    Anslist=sorted(anslist)
    flag=False
    judge=True
    for j in range(n):
        if Anslist[j]>0 and not flag:
            flag=True
        if Anslist[j]>0 and flag:
            judge=False
    if judge:
        print(ans%(998244353))
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)
keys = sorted(c.keys())
max = keys[len(keys)-1]
ok = True
if c[0] != 1:
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = True
            break
            count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*pow(c[i],c[i+1])
    ans =  ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

N = int(input())
D = list(map(int,input().split()))
tree = []
ans = 1

for i in range(max(D)+1):
    tree.append(D.count(i))
    
if tree.count(0) > 0:
    print(0)
elif not tree[0] == 1:
    print(0)
else:
    for j in range(len(tree)-2):
        ans *= pow(tree[j+1],tree[j+2])
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
def main():
  n = int(raw_input())
  items = map(int, raw_input().split())

  if items[0] > 0:
      print(0)
      return

  elems = []
  max_h = 0
  for i, e in enumerate(items):
    elems.append((i, e))
    if e > max_h:
      max_h = e
  
  graph = {}
  for i, e in sorted(elems, key=lambda x: x[1]):
    if e not in graph:
      graph[e] = []
    graph[e].append(i)
  
  dp = [0, ] * (max_h + 1)
  dp[0] = 1
  if len(dp) == 1:
      print(1)
      return

  dp[1] = 1

  for i in xrange(2, max_h+1):
      if i not in graph:
        print(0)
        return

      total = len(graph[i])
      prev = len(graph[i-1])
      dp[i] = dp[i-1] * prev**total

  print(dp[max_h])

main()

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-1]==0:
        break
    cnt=cnt*pow(ans[i-1],ans[i],mod)%mod

print(cnt%mod)

Submission status: Wrong Answer

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


def ruijo(a, b, mod):
    for i in range(10000):
        if b < 2 ** i:
            hoge = i
            break
    rui = []
    for i in reversed(range(hoge)):
        if b >= 2 ** i:
            rui.append(2 ** i)
            b -= 2 ** i
    x = 1
    hoje = 1
    for i in range(len(rui)):
        for j in range(rui[i]):
            hoje = (hoje * a) % mod

        x = (x * hoje) % mod
    return x


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

Sum = 1

for i in range(len(x)):

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

print(Sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
ans=1
error=0
if num[0]!=1:
    error=1
for i in range(1, max(d)+1):
    ans*=num[i-1]**num[i]
    if num[i]==0:
        error=1
if error==0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353
N = int(input())
D = list(map(int, input().split()))
c = collections.Counter(D)
##print(c)
ans = 1
for i in range(1, len(c)+1):
    ans *= c[i-1] ** c[i]
    ans = ans % mod
    ##print(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
def pow_k(x, n, mod):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2

    return K * x % mod
  
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
deep,a,b,c = 0,1,0,1
for i in range(n):
  if s[i] == deep:
    b += 1
  elif i == n:
    c *= a ** b
  elif s[i] == deep + 1:
    c *= a ** b
    a = b
    b = 1
    deep += 1
  else:
    c = 0
    break
    
  if i == n-1:
    if s[i] == deep:
      c *= pow_k(a, b, 998244353)
      c = c % 998244353
    elif s[i] == deep + 1:
      c *= pow_k(a, b, 998244353) 
      c = c % 998244353
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np


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


if D[0] != 0:
    print(0)
elif sum(D == 0) != 1:
    print(0)
else:
    D_counter = Counter(D)
    count = 1
    next = 1
    for i in range(1, max(D)+1):
        if i != next:
            print(0)
            break
        i = int(i)
        count = count * i**list(D_counter.values())[i]
        next += 1

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)
se1 = set(dd)
se2 = set(i for i in range(1, max(se1)+1))

if not(se1 & se2):
    print(0)
    exit()

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 collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

if L[0] != 0 or any(l == 0 for l in L[1:]):
    print(0)
    exit()

C = Counter(L)
C_L = sorted(C.items(), key=lambda x: x[0])
MOD = 998244353

ans = 1
for prev, cur in zip(C_L, C_L[1:]):
    val_p = prev[1]
    val_c = cur[1]
    ans *= val_p**val_c
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

ans = 1

Dict = {}

for i in range(N):
    if i == 0:
        if D[i] != 0:
            break
    else:
        if D[i] in Dict:
            Dict[D[i]] += 1
        else:
            Dict[D[i]] = 1

if len(Dict) != 0:

    for j in sorted(Dict.keys()):
        ans *= (j)**Dict[j]

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
import collections
def solve():
    sys.setrecursionlimit(100000)
    mod = 998244353

    N = int(input())
    D = list(map(int, input().split()))
    cnter = collections.Counter(D)
    cnter = sorted(cnter.items())

    ans = 1
    if cnter[0][0] != 0 or cnter[0][1] != 1 : 
        ans = 0
    elif len(cnter) == 1:
        ans = 1
    elif cnter[1][0] != 1:
        ans = 0
    else:
        for i in range(2, len(cnter)):
            if cnter[i][0] != i:
                ans = 0
                break

            else:
                ans = ans * modpow(cnter[i-1][1], cnter[i][1], mod) % mod
    
    print(ans)


def modpow(a,n,p):
  bi=str(format(n,"b"))
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
d = list(map(int,input().split()))
ans = 1
e = list(set(d))
i = 0
mod = 998244353
if e[0]!=0:
    ans=0
else:
    while (i<len(e)-1):
        if e[i]!=i:
            ans = 0
            break
            if e[i+1]!=i+1:
                ans=0
                break
        else:
            cnta=d.count(e[i])
            cntb=d.count(e[i+1])
            ans = ans*(cnta**cntb)%mod
        i+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = [int(_) for _ in input().split()]
c = Counter(d)
ans = 0
dmax = max(d)

f = 1
for i in range(dmax+1):
    f *= c[i]

if d[0] == 0 and f:
    ans = 1
    if dmax > 1:
        for i in range(2, dmax+1):
            ans *= c[i-1]**c[i]
            ans = ans%998244353
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=sorted(list(map(int, input().split())))
num=[0]*(max(d)+1)
num_=0
count=0
print(d)
j=0
for i in range(len(d)):
    if d[i]==j:
        num[j]+=1
    elif d[i]==j+1:
        num[j+1]+=1
        j+=1
    else:
        j+=1
print(num)
ans=1
error=0
if num[0]!=1:
    error=1
for i in range(1, max(d)+1):
    ans*=num[i-1]**num[i]
    if num[i]==0:
        error=1
if error==0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a=int(input())
d=[int(x) for x in input().split()]
d.sort()
z=max(d)
w=d.count(0)
if d[0]==0 and w==1:
  n=1
  for i in range(z):
    x=i+1
    r=d.count(x-1)
    q=d.count(x)
    n=(n*(r**q)%998244353)
  print(n)
else:
  print(0)

Submission status: Wrong Answer

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

temp = 1
count = 1
one_count = 1

if d[0] != 0 or d[1] != 1:
    print(0)
else:
    for i in range(1, n):
        if i == n-1:
            if d[i-1] != d[i]:
                temp = temp * (d[i] - 1) * one_count
        elif d[i] == d[i+1]:
            count += 1
        else:
            if d[i] == 1:
                one_count = count
                count = 1
            else:
                temp = temp * (d[i] - 1) * count * one_count
                count = 1

    print(temp % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from itertools import groupby
import numpy as np
def print_ans(N, input_line):
    """Test Case
    >>> print_ans(4, "0 1 1 2")
    2
    >>> print_ans(4, "1 1 1 1")
    0
    >>> print_ans(7, "0 3 2 1 2 2 1")
    24
    """
    ar = list(map(int,input_line.split()))
    ngflg = False
    if ar[0] != 0:
        ngflg = True
    ar = sorted(ar[1:])
    check_ar = list(set(ar))
    if check_ar[0] == 0:
        ngflg = True
    for i in range(len(check_ar) - 1):
        if check_ar[i] + 1 != check_ar[i + 1]:
            ngflg = True
    ar = np.array(ar)
    # tmp = np.split(ar, np.cumsum(np.unique(ar, return_counts=True)[1])[:-1])

    if ngflg:
        print("0")
    else:
        # ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        print(np.prod(ar) % 998244353)

if __name__ == '__main__':
    N = int(input().rstrip())
    ar = input().rstrip()
    print_ans(N, ar)

Submission status: Wrong Answer

Solution code:
import collections
  
N = int(input())
D = list(map(int, input().split()))
df = D[0]
D.sort()
ans = 1
e = 0
f = 0 
  
l = collections.Counter(D)  
 
for i in range(N):
  if l[i] != 0:
      ans *= l[i] ** l[i+1]
 
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1

for i in range(N):
  if i == 0:
    pass
  else:
    if D[i] == 0:
      f = 1
    
if D[0] != 0 or e == 1 or f==1:
  print(0)
elif N == 1:
  print(1)
else:
  print(ans%998244353)

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

    print(a)

if __name__ == "__main__":
    f_b()

Submission status: Wrong Answer

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

a = max(d)
ans = 1
if d.count(0) != 1:
    ans = 0

for i in range(1, a+1):
    if d.count(i) == 0:
        ans = 0
        break
    else:
        ans *= (d.count(i-1)**d.count(i))
        
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
else:
    import collections
    c = collections.Counter(d)
    c_sorted = sorted(c.items())
    u = [x[1] for x in c_sorted]
    x = 1
    for i in range(len(u)-1):
        x = x * (u[i] ** u[i+1])
                 
    print(x%998244353)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
vertex_list = list(map(int, input().split()))
if vertex_list[0] != 0:
    print(0)
else:
    maxx = max(vertex_list)
    list = []
    mark = 0
    for i in range(maxx):
        if i not in vertex_list:
            print("No")
            mark = -1
    if mark == 0:
        ans = 1
        for i in range(1, maxx+1):
            ans *= (i) ** vertex_list.count(i)
        print(ans)

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)
keys = sorted(c.keys())
max = keys[len(keys)-1]
ok = True
if c[0] != 1:
    ok = False
    print(0)
count = 0
for k in keys:
    #print(str(k)+str(count))
    if count != k:
        print(0)
        ok = True
        break
    count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*pow(c[i],c[i+1])
    ans =  ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin
N = int(F.readline())
d = list(map(int,F.readline().rstrip().split()))
ans_no = 0
ans = 1
max = max(d)
e = 998244353
def power(a,b): #aのb乗をeで割った余りを返す
    if b == 0:
        return 1
    elif b == 1:
        return a % e
    elif b%2 == 0:
        return power(a,b//2)**2 % e
    else:
        return power(a,b//2)**2*a % e

def ans_no():
    print(0)
    sys.exit()

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

for i in range(max+1):
    count = d.count(i)
    if i == 0 and count > 1:
        ans_no()
    if count == 0:
        ans_no()

    if i == 0 or i == 1:
        continue
    count_before = d.count(i-1)
    ans = ans * power(count_before, count)

print(ans)

Submission status: Wrong Answer

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


def main():
    from collections import defaultdict
    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
        dc = defaultdict(int)
        for i in d[1:]:
            dc[i] += 1
        for i in range(1, d[-1]):
            count = ((count % mod) * ((dc[i]**dc[i+1]) % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = 1
if n == 1:
  if l[0] == 0:
    print(1)
  else:
    print(0)

elif n == 2:
  if l[0] ==0 and l[1] == 1:
    print(1)
  else:
    print(0)

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

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

      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()
li = li[bisect.bisect(li,1):]
liv = list(set(li))
for i in range(len(liv)-1):
    if liv[i]+1 != liv[i+1]:
        print(0)
        exit()
lin = []
for key, value in groupby(li):
    lin.append((key,len(list(value))))
point = 1
for i in range(len(lin)):
    point *= pow(lin[i][0],lin[i][1],998244353)

print(point)

Submission status: Wrong Answer

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


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

maxd = max(d)
mem = [1 for i in range(maxd+1)]
for y in range(maxd):
  mem[y] = d.count(y)

count = 1
for i in range(maxd):
  count = count * mem[i] ** mem[i+1]
  count = count % 998244353
  
print(count % 998244353)

Submission status: Wrong Answer

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

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

#output
from collections import Counter
l = Counter(D).most_common()
l = sorted(l, key = lambda x:x[0])
M = len(l)

if M > 1:
    answer = l[1][1]
else:
    answer = 1
if D[0] != 0:
    answer = 0
elif l[0][1] != 1:
    answer = 0
else:
    for i in range(M-1):
        answer *= pow(l[i][1],l[i+1][1])
print(answer//2 % 998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
count=0
x=1
if listx[0]==0:
  for i in range(1,n):
    if i==n-1:#配列の後ろか確認
      x*=count+1
    elif listx[i]==listx[i+1]:#最後かどうか確認
      x*=count+2
      count=0
    else:
      count+=1
else:
  x=0
print(x)