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 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]):
            if not dc[i]:
                count = 0
            else:
                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
import collections

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

mod = 998244353
	
c = collections.Counter(d)
c = sorted(c.items(), key=lambda x:x[0])

if c==[(0,1)]:
	print(1)
	sys.exit()

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

ans=1
for i in range(1,len(c)):	
	ans = ans*(c[i-1][1])**c[i][1]
	if c[i-1][0]+1!=c[i][0]:
		print(0)
		sys.exit()

print(ans%mod)

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 = defaultdict(int)
for d in DD:
    cnts[d] += 1

m = max(DD)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ans = 1
ans_ = 1
for i in range(len(D_)):
    temp = D_[i]
    if i == 0 and temp > 1:
        print(0)
        ans_ = 0
        break
    elif i != len(D_)-1 and temp ==0:
        print(0)
        ans_ = 0
        break
    elif i > 0:
        ans *= D_[i-1] ** D_[i]
        ans %= 998244353
if ans_:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
a=1
b=1
d=sorted(d)
if n==1:
    ans=0
else:
    for j in range(0,n-1):
        if d[j+1]-d[j]>1:
            ans=0
        
    if d[0]!=0 or d[1]==0:
        ans=0
    else:
        for i in range(1,n-1):
            if d[i]==d[i+1]:
                a+=1

            else:
                ans=ans*(b**a)
                b=a
                a=1
ans=ans*(b**a)
ans=ans%998244353
print(ans)

Submission status: Wrong Answer

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

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

ans = 1
old = 1
now = 1
c = 0

for q in range(1,len(a)):
  ans %= 998244353

  if now != a[q]:
    if now+1 != a[q]:
      print 0
      exit(0)
    else:
      ans = ans * pow(old,c)
      old = c
      c = 1
      now = a[q]
  else:
    c += 1
ans = ans * pow(old,c)

ans %= 998244353
print ans

Submission status: Wrong Answer

Solution code:

N = int(input().strip())
array = list(map(int, input().strip().split(' ')))
if array[0] != 0:
    count = 0

else:
  count = 1
for i in range(N//2 + 1):
    if array[i] != 0:
        count = count * array[i]
    if array[N-i-1] !=0:
        count  = count * array[N-i-1]
if N % 2 !=0:
    if array[(N//2)] != 0:
        count = count // array[(N//2)]
            
ans = count % 998244353 
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))
s = list(set(D))

if D[0] == 0 and ((len(D) - np.count_nonzero(D)) == 1) and s[-1] == len(s)-1:
    print(D[1:].prod() % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

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

counted = collections.Counter(D)

if D[0] != 0 or counted[0] !=1:
    print("0")
    exit()

#calc
result = 1
x = counted[1]
for i in range(2,N+1):
    y = counted[i]
    if y!= 0:
        result = result * pow(x,y) %998244353
        x = y
print(result)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = Counter(D)
ans = reduce(mul, filter(lambda x: x!= 0, D))
for i, (n, c) in enumerate(sorted(counter.items())):
    # n = int(n)
    if i != n:
        ans = 0
        break
print(ans % M)

Submission status: Wrong Answer

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

if D[0] != 0:
    val = 0
else:
    tmp = 1
    for n in range(1, N):  #1からN-1
        tmp = tmp * D[n]
    val = tmp % 998244353
print(val)

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:
    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
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
r = 1
for i in range(mm):
    r = (r * pow(cc[i], cc[i+1])) % MM
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
count = [0] * (N)
ans = 1
if (D[0] != 0):
    print(0)
    exit()
for d in D:
    count[d] += 1
for i in range(N - 2):
    if (count[i] == 0 and count[i + 1] != 0):
        print(0)
        exit()
for i in range(1, N - 1):
    if (count[i] != 0):
        ans *= (count[i] ** count[i + 1]) % 998244353

print(ans % 998244353)

Submission status: Wrong Answer

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

MOD = 998244353  # type: int


def sumC(n):
    ret=nCr=1
    for i in range(n):
        nCr_1=nCr*(n-r)//(r+1)
        ret+=nCr_1
        nCr=nCr_1
    return(ret)

def baai(n1, n2):
    return(n1**n2%MOD)

def solve(N: int, D: "List[int]"):
    if D[0]!=0:
        print(0)
    else:
        answer=1
        bak=D.count(1)
        kyori=2
        hen=bak
        while True:
            cnt=D.count(kyori)
            if cnt==0:
                break
            answer*=baai(bak, cnt)
            bak=cnt
            kyori+=1
        print(answer%MOD)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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(0,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:
N = int(input())
D = list(map(int,input().split()))

count = 1
max = 0
NUM = [0 for i in range(N)]

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

for i in range(N):
    NUM[D[i]] += 1
    if max < D[i]:
        max = D[i]

for j in range(1,N):
    if max > 2:
        NUM[j] += 1


for k in NUM:
    if k != 0:
        count *= k

result = count % 998244353
print(result)

Submission status: Wrong Answer

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

a = max(d)
b = []
c = 1
ans = c

for i in range(a + 1):
    b.append(d.count(i))
    
if b[0] != 0: 
    for j in range(1, a + 1):
        if b[j] == 0:
            ans = 0
            break
        else:
            c *= (b[j-1] ** b[j] )
else:
    ans = 0
    
print(c % 998244353)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# 2019/11/9

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

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

res={}
for e in d:
    res[e]=res.get(e,0)+1

if res[0]>1:
    print(0)
    exit()

def cmb(n,r,mod):
    global memo
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i%mod)
    ret=fac[n]*pow(fac[r]*fac[n-r]%mod,mod-2,mod)%mod
    return ret


ans=1
pre=res.get(1,-1)
if pre==-1:
    print(0)
    exit()

memo={}

cnt=0
for i in range(2,len(res)):
    tmp=res.get(i,-1)
    if tmp==-1:
        print(0)
        exit()
    j=1
    while j<=(tmp-1)//2:
        
        cnt+=cmb(tmp,j,mod)*2
        j+=1
    if tmp%2==0:
        cnt+=cmb(tmp,tmp//2,mod)
    cnt+=pre
    ans=(ans%mod)*(cnt%mod)
    cnt=0
    pre=tmp
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]+1):
            if not dc[i]:
                count = 0
            else:
                count = ((count % mod) * (dc[i]**dc[i+1] % mod)) % mod
        prev = 0
        for i in d[1:]:
            if i == prev + 1 or i == prev:
                prev = i
                continue
            else:
                count = 0
                break
        print(count % mod)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np


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


def q2(n, D):
    MAXINT = 998244353
    counts = np.sum(D == np.arange(n)[:, None], axis=1)
    idx = np.where(counts == 0)[0]
    minidx = np.min(idx)
    if len(idx) == n - minidx and (idx == np.arange(minidx, n)).all():
        return int(np.prod([counts[i] ** counts[i + 1] for i in range(minidx)])) % MAXINT
    return 0


if __name__ == '__main__':

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

Submission status: Wrong Answer

Solution code:
import sys
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
r = 1
for i in range(mm):
    r = r * pow(cc[i], cc[i+1]) % MM
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
E = [D.count(1)]
answer = 1

#if D[0] != 0:
 #print('0')
#else:
for i in range(1, max(D)):
  E.append(D.count(i + 1))
  answer *= E[i - 1] ** E[i]
  print(answer % 998244353)

Submission status: Wrong Answer

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

n = int(input())
d = list(map(int,input().split()))
d = sorted(dict(Counter(d)).items(),key=lambda x:x[0])
cnt = d[0][1]

for i in range(len(d)):
    if i != d[i][0]:
        print('0')
        break
    elif d[i][1] == 1:
        cnt *= d[i-1][1]
    else:
        cnt *= d[i][1]**i-1
else:
    print(cnt%998244353)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

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

counted = collections.Counter(D)

if D[0] != 0 or counted[0] !=1:
    print("0")
    exit()

#calc
result = 1
x = counted[1]
for i in range(2,N+1):
    y = counted[i]
    if y!= 0:
        result = result * pow(x,y)
        x = y
print(result%998244353)

Submission status: Wrong Answer

Solution code:
import collections

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

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

cntsum = 1
judge_cnt = 0

if e[1] == 0:
    print(0)
    exit()

m = max(e)
e2 = dict(sorted(e.items()))
e3 = list(e2.values())
e4 = list(e2.keys())
#print(e2)
#print(e3)
#print(e4)

tmp=0
for i in e4:
    if i-tmp>=2:
        print(0)
        exit()
    tmp=i
    
cntsum = 1
for i in range(1, len(e3)):
    cntsum *= e3[i - 1] ** e3[i]
print(cntsum)

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 = defaultdict(int)
for d in DD:
    cnts[d] += 1

m = max(DD)

if DD[0] != 0:
    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:
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ans = 1
D_n = [D.count(i) for i in range(max(D) + 1)]
print(D_n)
#n1が0ではない、もしくは他に0がある
if D[0] != 0 or D.count(0) != 1:
  ans = 0
else:
  for i in range(1, max(D)):
    ans *= D_n[i] ** D_n[i + 1]
    if ans >= mod:
      ans %= mod
print(ans)

Submission status: Wrong Answer

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

n=int(input())
l=list(map(int,input().split()))
l.sort()
if l[0]!=0:
    print(0)
elif n==1:
    print(1)
else:
    c=1
    last=0
    check=0
    setl=set(l)
    setl=list(setl)
    for _ in setl[1:]:
        if _!=last+1:
            print(0)
            sys.exit()
        last+=1
    m=[]
    last=0
    num=1
    for i in range(1,n):
        if l[i]!=last:
            m.append(c%998244353)
            c=1
            last+=1
        else:
            c+=1
        if i==(n-1):
            m.append(c)
    for k in range(1,len(m)):
        if m[k] == 1:
            num*=m[k-1]
        else:
            if num==1:
                num*=m[k]
            else:
                num=num**m[k]
        num%=998244353
    print(num)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
D = list(map(int,input().split()))
ans = 1
c = Counter(D)
for i in range(1,N):
  if c[i]==0:
    break
  ans = ans*pow(c[i-1],c[i])
print(int(ans%998244353))

Submission status: Wrong Answer

Solution code:
import os
N=int(input())
a=list(map(int, input().split()))
if not (a[0]==0):
  print(0)
else:
  m=max(a)
  b=[0]*(m+1)
  for i in a[1:]:
    b[i]+=1
  res=1
  #print(b)
  for i in range(2,len(b)):
    res*=b[i-1]**b[i]
  
  print((res+b[0])%998244353)

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0:
        continue
    else:
        ct *= b[i-1]**b[i]
if b[0] != 1:
    print(0)
else:
    print(ct%998244353)

Submission status: Wrong Answer

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

r = [None] * N
m = 0

for i, j in enumerate(D):
    if i == 0 and j != 0:
        print("0")
        exit()
    r[j] = 1 if r[j] is None else r[j] + 1
    if j > m:
        m = j

result = 1
pre = None

for i, x in enumerate(r):
    if x is None:
        if i != m + 1:
            print("0")
            exit()
        else:
            break
    if i < 2:
        pre = x
        continue
    result *= pre**x
    pre = x


print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = [int(a) for a in input().split()]

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()

k = max(A)

c = 1
R = 1
result = 1


for i in range(k):
    L = A.count(i + 1)
    for j in range(L):
        result *= R % 998244353

    R = L

    if result == 0:
        print(0)
        exit()

print(result)

Submission status: Wrong Answer

Solution code:
import collections


def mod_pow(a, n, mod):
    if a == 0 or n == 0:
        return 0
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    if counter[0] != 1:
        return 0
    if 0 in counter.values():
        return 0
    if len(counter) < 2:
        return 1
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

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


    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def ContinueCnt(A):
    datas = [_ for _ in range(max(A) + 1)]
    counts = [0] * len(datas)
    if set(datas) != set(A):
        print(0)
        exit()
    for j in range(max(A) + 1):
        counts[j] = A.count(j)
    return datas, counts

def power_func(a, n, p):
    bi = str(format(n, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res

INF = 998244353

N = int(input())
D = list(map(int, input().split()))
D_datas, D_counts = ContinueCnt(D)
# print(D_datas, D_counts)  # for debug

# first check zero
if D_counts[0] != 1:
    print(0)
    exit()

ans = 1
# check 1 ~ max(D)
for i in range(1, max(D_datas) + 1):
    ans *= power_func(D_counts[i - 1], D_counts[i], INF)
    # print("now = ", ans)  # for debug

print(ans % INF)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))

lens = [0] * N

for d in D:
    lens[d] += 1

total = 1
prev_l = 1
for i, l in enumerate(lens):
    if i == 0:
        prev_l = l
        if l != 1:
            total = 0
            break
        continue
    total *= (prev_l**l)
    total %= MOD
    prev_l = l

print(total%MOD)

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

Submission status: Wrong Answer

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

setD = list(set(d))
setD.sort()
ans = 1
nodeMulti = 1

if d[0] > 0:
        print(0)
        exit()
else:
        c = Counter(d)
        for s in setD:
                ans *= math.factorial(c[s])
                nodeMulti *= c[s]
        nodeMulti //= setD[-1]
        ans *= nodeMulti
        print(ans%998244353)

Submission status: Wrong Answer

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

if D[0] != 0:
  print(0)
if N == 1:
  print(1)
else:
  print(ans%998244353)

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 not D.count(0) == 1:
    print(0)
elif tree[0] > 1:
    print(0)
else:
    for j in range(len(tree)-2):
        ans *= pow(tree[j+1],tree[j+2])
    print(ans)

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]
    result *= prenum**nownum
    result %= 998244353
 
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
MM = 998244353
n, = map(int, input().split())
xs = list(map(int, input().split()))
mm = max(xs)
cc = [0] * n
for x in xs:
    cc[x] += 1
for i in range(mm+1):
    if cc[i] == 0:
        print(0)
        sys.exit()
r = 1
for i in range(mm):
    r = r * pow(cc[i], cc[i+1]) % MM
    print(i, r)
print(r)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
ans = 0
if D[0] == 0:
    ans = 1
    for i in range(2, max(D)+1):
        ans = ans * (D.count(i-1)**D.count(i))
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter 
import sys

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

mod = 998244353

D.sort()
d = list(Counter(D).items()) 

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

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 or c[i]==0:
            flag=False
            break
        else:
            ans=ans*(c[i-1]**c[i])%998244353

    print(ans%998244353 if flag else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
inputs = sys.stdin.readlines()
n = int(inputs[0])
A = list(map(int, inputs[1].split()))
MOD = 998244353

B = sorted(Counter(A).items())
C = [b[1] for b in B]
if all([i == k for i, (k, v) in enumerate(B)]) and C[0] == 1:
    ans = 1
    for i in range(1, len(C)-1):
        ans *= (C[i] ** C[i+1]) % MOD
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import collections


def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    counter = collections.Counter(d)
    if counter[0] != 1:
        return 0
    if 0 in counter.values():
        return 0
    if len(counter) < 2:
        return 1
    pows = [mod_pow(a=counter[i - 1], n=counter[i], mod=MOD) for i in
            range(1, max(counter.keys()) + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

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
mb = 0
for i in D:
    if i == 0:
        mb += 1
    else:
        break
#print(mb)
S = mb
Sb = 1
for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        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 = list(map(int,input().split()))
db = [0] * n
MOD = 998244353

#距離iの頂点の数をdb[i]に保存
for i in range(n):
    db[d[i]] += 1

#末尾に連続する0を削除
if (db[n-1] == 0):
    l = n-1
    for i in range(1,n):
        tmp = db[n-i]
        if (tmp == 0) : l = n-i 
        else : break
    
    del db[l:n]


if (d[0] != 0)|(db[0] != 1):
    print(0)
    exit()
if (len(db) <= 2):
    print(len(db)-1)
    exit()

db.append(1)
ans = 1

for i in range(len(db)-1):
    tmp = (db[i]**db[i+1]) % MOD
    ans *= tmp

print(ans)

Submission status: Wrong Answer

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

n = int(input())
d = list(map(int,input().split()))
d = sorted(dict(Counter(d)).items(),key=lambda x:x[0])
cnt = d[0][1]

for i in range(len(d)):
    if i != d[i][0]:
        print('0')
        break
    elif d[i][1] == 1:
        cnt *= d[i-1][1]
    else:
        cnt *= d[i][1]**i-1
else:
    print(cnt)

Submission status: Wrong Answer

Solution code:
a=int(input())
d=[int(x) for x in input().split()]
d.sort()
z=max(d)

if d[0]==0:
  n=1
  for i in range(z):
    x=i+1
    r=d.count(x-1)
    q=d.count(x)
    n=n*(r**q) 
  print(n%998244353)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
MOD = 998244353
N = int(input())
D = list(map(int, input().split()))

lens = [0] * N

for d in D:
    lens[d] += 1

total = 1
prev_l = 1
for i, l in enumerate(lens):
    if i == 0:
        prev_l = l
        if l != 1:
            total = 0
            break
        continue
    total *= ((prev_l**l)%MOD)
    prev_l = l

print(total%MOD)

Submission status: Wrong Answer

Solution code:
# 2019/11/9

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

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

res={}
for e in d:
    res[e]=res.get(e,0)+1

if res[0]>1:
    print(0)
    exit()

def cmb(n,r,mod=10**9+7):
    fac=[1,1]
    for i in range(2,n+1):
        fac.append(fac[i-1]*i%mod)
    ret=fac[n]*pow(fac[r]*fac[n-r]%mod,mod-2,mod)%mod
    return ret


ans=1
pre=res.get(1,-1)
if pre==-1:
    print(0)
    exit()

cnt=0
for i in range(2,len(res)):
    tmp=res.get(i,-1)
    if tmp==-1:
        print(0)
        exit()
    j=1
    while j<=(tmp-1)//2:
        cnt+=cmb(tmp,j)*2
        j+=1
    if tmp%2==0:
        cnt+=cmb(tmp,tmp//2,mod)
    cnt+=pre
    ans=(ans%mod)*(cnt%mod)
    cnt=0
    pre=tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

cnt = collections.Counter(D)
if D[0] != 0:
    ans = 0
elif cnt.most_common()[-2][1] == 0:
    ans = 0
else:
    ans = 1
    for i in range(1, max(D)+1):
        ans *= i ** cnt[i]

print(ans%998244353)

Submission status: Wrong Answer

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

MOD = 998244353

occ = [0 for i in range(N+5)]
for d in D:
    occ[d] += 1

if occ[0] != 1:
    print(0)
    quit()

cur = 1
for i in range(1, N+5):
    cur *= pow(occ[i - 1], occ[i])
    cur %= MOD
print(cur % MOD)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())

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

counted = collections.Counter(D)

if D[0] != 0 or counted[0] !=1:
    print("0")
    exit()


#calc
result = 1
x = counted[1]
for i in range(2,N):
    y = counted[i]
    if y!= 0:
        result = result * pow(x,y)
        x = y
print(result%998244353)

Submission status: Wrong Answer

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

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

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

for i in range(n-1):
    if max(dd[:i+1])+1 >= dd[i] > 0:
        ans *= dd[i]

print(ans)

Submission status: Wrong Answer

Solution code:
#B
N = int(input())
D_list = [int(s) for s in input().split(" ")]

res = 1
for i in range(0, max(D_list)):
    res *= D_list.count(i) ** D_list.count(i+1)

print(res % 998244353)