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:
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(1,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())
D = list(map(int,input().split()))
D.sort()
def count(D):
    s = [1]
    for i in range(1,len(D)):
        if D[i] == D[i-1]:
            s[len(s)-1] = s[len(s)-1] + 1
        else:
            s.append(1)
    return(s)
def tree(L):
    t = 1
    if L[0] != 1:
        return 0
    else:
        for i in range(1,len(L)):
            t = t * (L[i-1]**L[i])
        return t
print(tree(count(D)))

Submission status: Wrong Answer

Solution code:
n = input()
string = input()
list = string.split()
num = []
for i in list:
  num.append(int(i))
ans = 0

if num[0] == 0 and num.count(0) == 1:
  ans = 1
  temp_num =1
  for i in range(max(num)):
    ans *= temp_num
    temp_num = num.count(i+1)
    if temp_num == 0:
      ans = 0
      break

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

INF = 998244353

D_max = max(Dlist)
cnt = [0] * (D_max + 1)

dic = Counter(Dlist)
for k, v in dic.items():
    cnt[k] = v

ans = cnt[0]

if ans != 1:
    print(0)
else:
    for i in range(D_max):
        ans = ans * (((cnt[i] % INF) ** cnt[i+1]) % INF)
        ans = ans % INF
    
    print(ans % INF)

Submission status: Wrong Answer

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

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

ans = 1
if d[0] == 0 and d.count(0) == 1:
    l = [0 for i in range(10**5+10)]
    for i in range(n):
        l[d[i]] += 1
    
    count = l[0] + l[1]
    for i in range(2,10**5+10):
        if l[i] == 0:
            break
        else:
            ans = ans * l[i-1]**l[i]
   #         print(l[i-1]**l[i],ans)
            count += l[i]
    if count != n:
        ans = 0
    print(ans)
    
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
n = int(input())
D = list(map(int,input().split()))
if (D[0] != 0):
  print(0)
  sys.exit(0)
c = Counter(D)
if (c[0] > 1):
  print(0)
  sys.exit(0)
ans = 1
for i in range(1,max(D)+1):
  ans *= c[i-1]**c[i]
print(ans % 998245343)

Submission status: Wrong Answer

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

a=D.count(1)
b=1
ans=1

if D[0]!=0:
  print(0)
else:
  for i in range(2,N):
    b=D.count(i)
    ans*=(a**b)
    a=b
  print(ans)

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

N=one_int()
D=many_int()

num=998244353

dicts={}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        try:
            sums *= (dicts[keys[i]]**dicts[keys[i+1]])
            sums = sums%num
        except:
            sums=0
            break
print(sums)

Submission status: Wrong Answer

Solution code:
from collections import Counter
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):
        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()))

max_D = max(D)
count = 0
C = [[] for _ in range(N)]
X = []
ans = 1

for n in range(N):
    C[D[n]].append(D[n])

for i in range(1, max_D):
    if len(C[i]) == 0:
        count += 1
        break

if D[0] != 0:
    count += 1
elif count > 0:
    pass
elif len(C[0]) != 1:
    count += 1
else:
    for j in range(1,max(D)+1):
        t = len(C[j-1]) ** len(C[j])
        X.append(t)
    for x in X:
        ans = x * ans

if count > 0:
    print(0)
else:
    print(int(ans))

Submission status: Wrong Answer

Solution code:
# B
from collections import Counter
mod = 998244353
n = int(input())
dli = list(map(int, input().split()))

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:

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
mod = 998244353
ans = 1

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

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

import collections
d_count = collections.Counter(d)

for i in range(n):
     ans = ans * (d_count[i] ** d_count[i+1]) % mod
     
     if i > 0 and d_count[i] == 0 :
         print(0)
         sys.exit()
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]-D[i-1] > 1:
                ans = 0
                break
            if D[i] == num:
                cnt += 1
            elif num == 1:
                prev = cnt
                cnt = 1
                num += 1
            else:
                ans *= prev**cnt
                ans %= mod
                prev = cnt
                cnt = 1
                num += 1
        ans *= prev**cnt
        ans %= mod
    else:
        ans = 0
else:
    ans = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
NUMBER = 998244353

N = int(input())
D = list(map(int, input().split()))
bincnt = np.bincount(D)
if (bincnt==0).sum() > 0:
    print('0')
elif bincnt[0]!=1:
    print('0')
else:
    val = 1
    for i in range(2, bincnt.shape[0]):
        for _ in range(bincnt[i]):
            val = (val*bincnt[i-1]%NUMBER)
    print(val)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect
import collections

mod = 998244353
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
D = LI()

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

if 0 in D[1:]:
    print(0)
    sys.exit()


D.sort()
c = collections.Counter(D)
ans = 1
parents = 1
for key in c.keys():
    ans *= parents**c[key]
    ans = ans % mod
    parents = c[key]

print(ans)

Submission status: Wrong Answer

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

# print(Ds)

from collections import defaultdict
d = defaultdict(int)

d_max = Ds[-1]
for D in Ds:
    d[D] += 1

ans = 1

for i in range(1,d_max+1):
    ans *= pow(d[i-1],d[i],mod)%mod
if d[0] > 1:
    print(0)
else:
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
if D[0]!=0:
  print(0)
else:
  tmp=Counter(D)
  ans=1
  for i in tmp.keys():
    if i==0:
      continue
    ans*=tmp[i-1]**tmp[i]
  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]==0:
	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:
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:
  out = 1
  idx = np.hstack([np.where(np.diff(D) == 1)[0], N-1])
  num = np.diff(idx)
  for i in np.arange(1, len(num)):
    out *= np.power(num[i-1]%998244353, num[i])
  print(out%998244353)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
for i in range(1, len(A)):
    B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

ans = 1
if A[0] != 0:
    ans = 0 

for i in range(1, max_B):    
    if B[i] == 0:
        ans = 0 
        break
    else:
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    if (i in mapping) and (i+1 in mapping):
      ans *= mapping[i]**(mapping[i+1])
    else:
      ans = 0
      break
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
from collections import Counter


def main():
    n = int(input().strip())
    d = list(map(int, input().strip().split()))
    e = sorted(list(set(d)))
    for i, v in enumerate(e):
        if i != v:
            print(0)
            return
    v = dict(Counter(d))
    if v[0] != 1:
        print(0)
        return
    i = 0
    ans = 1
    while True:
        if i in v:
            if i == 0:
                i += 1
                continue
            ans *= v[i-1] ** v[i]
            ans %= 998244353
        else:
            break
        i += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

if d_list[0] != 0:
  print(0)
elif 0 in d_list[1:]:
  print(0)
else:
  d_count_dict = collections.Counter(d_list)
  start_num = -1
  start_cnt = 0
  answer = 1
  last = 1
  for num, cnt in d_count_dict.items():
    if num != start_num + 1:
      answer = 0
    else:
      answer *= last ** cnt
      last = cnt
      start_num = num
  print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
d = list(map(int, input().split()))

cnt = dict()
for k in d:
    if k in cnt:
        cnt[k] += 1
    else:
        cnt[k] = 1

mod = 998244353

keys = cnt.keys()
pre = -1
rst = 1

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

for k in sorted(keys):
    if (pre + 1) != k:
        rst = 0
        break
    pre = k

    if k == 0:
        continue

    rst = (rst * (cnt[k-1] ** cnt[k])) % mod
    
print(rst)

Submission status: Wrong Answer

Solution code:
import bisect

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

D.sort()

key = max(D) + 1
count_list = [0] * key

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

counter = 1
for i in range(1, key - 1):
    counter *= count_list[i]**count_list[i + 1]

if 0 in count_list:
    counter = 0
print(counter)

Submission status: Wrong Answer

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

Ans=1
for i in range(max(Ds)):
    Ans *= Ds.count(i)**Ds.count(i+1)
print(Ans)

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):
        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 main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for k, v in c.items():
        if k == 0 or k == 1:
            continue
        elif v == 0:
            return print(0)
        else:
            ans *= (max(0, 2**(v) - c[k-1]) + c[k-1]) % MOD
            ans = ans % MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

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 or n <2:
    print(0)
else:
    print(count%mod)

Submission status: Wrong Answer

Solution code:
N = int(input().strip())
D = list(map(int, input().strip().split(" ")))
d = list(set(D))

if min(d) > 0 or max(d) >= len(d):
    print(0)
    exit()

c = 1
x = [0] * len(d)
for i in D:
    x[i] += 1
for i in range(1,len(d)):
    c *= x[i-1]**x[i]

print(c % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
import sys
n = int(input())
d = list(map(int, input().split()))
c = collections.Counter(d)
if d[0] != 0:
    print(0)
    sys.exit()
ans = 1

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

Submission status: Wrong Answer

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

ans = 1
if min(d) != 0:
  ans = 0
for i in range(1,max(d)+1):
  ans = ans * i**d.count(i)

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
sys.setrecursionlimit(10**6+10)
N=int(input()) 
d=list(map(int, input().split())) 
if d[0] != 0:
  print(0)
  sys.exit()
  
  
c = collections.Counter(d)
c = dict(collections.Counter(d))

max_key = max(c.keys())

count = 1
for i in range(2,max_key+1):
  a = c.get(i, -1)
  b = c.get(i-1, -1)
  if a == -1 or b == -1:
    print(0)
    sys.exit()
  count = (count * (b**a))%998244353

print(count)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
D.sort()
ans = 1
hoge = 1
hoge2 = 1

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

for i in range(1,N):
    if D[i] == D[i-1]+1:
        ans = (hoge*ans)%MOD
        hoge = hoge2
        hoge2 = 1
    elif D[i] == D[i-1]:
        ans = (hoge*ans)%MOD
        hoge2 += 1
    else:
        print(0)
ans = (hoge*ans)%MOD
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]
    num %= 998244353
print(num)

Submission status: Wrong Answer

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

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:
n = int(input())
d_array = [int(x) for x in input().split()]
counter = {x: 0 for x in range(-1, 10 ** 5 + 1)}
for i in d_array:
    counter[i] += 1
MOD = 998244353

ans = 1
for num in set(d_array):
    if num == 0:
        continue
    if counter[num-1] == 0:
        print(0)
        exit()
    ans *= (counter[num-1])**counter[num]
    ans = ans % MOD
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

d.sort()

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)

Submission status: Wrong Answer

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

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

for i in range(1,max(D)):
   ans *= D.count(i) ** D.count(i+1)

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 += 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%998244353)
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:
            if val != 1:
                print(0)
                break
        elif i == 1:
            pre = val
        else:
            ret = pow(pre, val, mod) * ret % mod
            pre = val
else:
    print(ret)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	n = int(input())
	d = list(map(int,input().split()))
	z = defaultdict(int)
	for i in d:
		z[i] += 1
	mx = max(d)
	if(z[0]!=1):
		print(0)
		return
	for i in range(1,mx+1):
		if(z[i]==0):
			print(0)
			return
	ans=1
	for i in range(mx):
		ans*=z[i]**z[i+1]
	print(ans)

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()

Submission status: Wrong Answer

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

import collections
def counter_list(A):
  counter = collections.Counter(A)
  counter =  [list(e) for e in counter.items()]
  counter.sort() #sortしたい場合はつける
  return counter

if(D[0] != 0): ans = 0
else: 
  D = counter_list(D)
  if(D[0][1] != 1):
    ans = 0
  else:
   ans = 1
   for i in range(len(D)-1):
    if(i >= 1):
      a = D[i][1]%998244353
      b = D[i+1][1]
      ans = ans%998244353
      ans = ans*(a**b)
      ans = ans%998244353
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):
    return 0


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from sys import exit

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

c = {}
for i in D:
    if i in c:
        c[i] += 1
    else:
        c[i] = 1

d = list(c.keys())
d.sort()
if c[d[0]] != 1:
    print(0)
    exit()

result = 1
for i in range(d[1], N):
    if i not in c:
        if max(d) == i - 1:
            break
        else:
            print(0)
            exit()
    result = result * (c[i - 1] ** c[i]) % 998244353
print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(10**5)]
MOD = 998244353

max_B = -1
for i in range(1, len(A)):
    B[A[i]-1] += 1
    if A[i] > max_B:
        max_B = A[i]

ans = 1
if A[0] != 0:
    ans = 0 

for i in range(1, max_B):    
    if B[i] == 0:
        ans = 0 
        break
    else:
        print(ans)
        ans = (ans * (B[i-1] ** B[i])%MOD)%MOD

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

prev = 1
if (0 in m) and (m[0] == 1):
    s = 1
    for i in range(1, 10 ** 5 + 1):
        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:
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    if arr[0] != 0:
        print(0)
        return
    
    mod = 998244353
    dist = {}
    arr1 = []
    for i in arr:
        if i not in dist.keys():
            dist[i] = 1
            arr1.append(i)
        else:
            dist[i] += 1

    if dist[0] > 1:
        print(0)
        return

    arr1.sort()

    #print(dist)
    ways = 1
    for i in range(1,len(arr1)):
        if arr1[i] - arr1[i-1] != 1:
            print(0)
            return
        prev = (ways*dist[arr1[i-1]])%mod
        curr = dist[arr1[i]]
        ways = prev*pow(prev,curr-1,mod)
        ways = ways%mod
        #print(ways)

    print(ways)
         

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print('No')

Submission status: Wrong Answer

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

if d[0]!=0 or c[0]!=1:
  print(0)
  
else:
  for j in range(2,n):
    ans*=c[j]**c[j-1]
  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 and A[0] == 0:
    print(1)
    exit()
else:
    print(0)
    exit()

D[1] = A.count(1)
ans = 1
if A[0] > 0:
    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:
from collections import Counter

n = int(input())
d = list( map(int, input().split()))
c=Counter(d)
dmax = max(d)
MOD = 998244353

if len(c)-1 != dmax:
    print(0)
    exit()

ans = 1

for i in range(1,dmax):
    ans *= c[i]**c[i+1]
    ans %= MOD

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

F = False
for i, d in enumerate(D):
    if i == 0:
        if d != 0:
            F = True
            break
    else:
        if d == 0:
            F = True
            break
            
L=sorted(set(D))
for i in range(len(L)-1):
    if (L[i+1]-L[i]) != 1:
        F=True
        break
        
s=1
for l in L[:-1]:
    if l<1:continue
    for i in range(D.count(l+1)):
        s*=D.count(l)
        
print(0 if F else s)

Submission status: Wrong Answer

Solution code:
n=int(input())
D=list(map(int,input().split()))
T=[[] for _ in range(max(D)+1)]
for i in range(n):
    T[D[i]].append(i+1)
a=1
for j in range(1,len(T)):
    if T[j]==[]:
        print(0)
        exit()
    else:
        a*=len(T[j-1])**len(T[j])
        a%=998244353
print(a)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

lis = [0] * (10 ** 5 + 10)

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

for i in D:
    maxi = max(maxi,i)
    lis[i] += 1

ans = 1
for i in range(maxi + 1):

    if i == 0 and lis[i] != 1:
        ans = 0
        print (0)
        sys.exit()
    elif i != 0:
        #print (ans,lis[i-1],lis[i])
        ans = ans * ( lis[i-1] ** lis[i] ) 
        ans %= 998244353

#print (lis)
print (ans % 998244353)

Submission status: Wrong Answer

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