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:
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:
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 *= 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:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0) 
    
    else:
        #d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        ans = 1
        tmp = 1
        for i,j in items:
            if i == 0:
                continue
            
            ans *= i**j
            #print(ans)
            #tmp = j
        
        #ans *= i*
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

INF = 998244353

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

if D.count(0) != 1:
    print(0)
    exit()

res = 1
pre = 1

for i in range(1,N):
    now = D.count(i)
    if now == 0:
        break
    res = res * pre ** now % INF
    pre = now

print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
N = int(stdin.readline().rstrip())
_A = stdin.readline().rstrip().split()
A = [int(s) for s in _A]
B = []
Max = max(A)
Tes = True
for el in range(Max + 1):
    if (not el in A):
        Tes = False
        break
    B.append(A.count(el))

if (Tes):
    res = 1
    for el in range(1, len(B)):
        res *= B[el - 1] ** B[el]

if (Tes):
    print(res)
else:
    print('0')

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 len(D) == 1:
    if D[0] == 0:
        print(1)
else:
    if D[0] == 0 and (np.count_nonzero(D) == len(D)-1) and (s[-1] == len(s)-1):
        print(D[1:].prod() % 998244353)
    else:
        print(0)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    D.sort()
    mod = 998244353
    ans = 1
    distance = 0
    prev = 1
    now = 1
    for i in range(N):
        if D[i] == 0:
            continue
        elif D[i] == distance:
            now += 1
        elif D[i] == distance + 1:
            ans = (ans % mod) * (prev ** now % mod) % mod
            prev = now+0
            now = 1
            distance += 1
        else:
            ans = 0
            break
    else:
        ans = (ans % mod) * (prev ** now % mod) % mod
    
    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
else:
    ans = 1
    for i in range(1, max(D)+1):
        if cnt[i] == 0:
            ans = 0
            break
        else:
            ans *= cnt[i-1] ** cnt[i]

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
d = list(map(int,input().split()))
ans = 1
e = list(set(d))
i = 0
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)
        i+=1
print(ans)

Submission status: Wrong Answer

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

N = input1[0]
D = input2

counter = collections.Counter(D)

ans = 1


D.sort()
D_numpy = np.array(D)
if (np.diff(D_numpy)<=1).prod():
  if counter[0] != 1:
    ans = 0
  else:
    for i in range(len(counter)-1):
      ans *= counter[i]**counter[i+1]
      if ans >= 998244353:
        ans = ans%998244353

else:
  ans = 0

print(ans)
# print(ans)

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 = []
for i in range(n):
    counts.append(d.count(i))
    
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 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)
        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:
n=int(input())
d=list(map(int,input().split()))
ans=1
c=[0 for i in range(max(d)+1)]
for x in d:
  c[x]+=1
if d[0]!=0 or (0 in c):
  print(0)
  exit()
p=1
for x in c:
  ans*=p**x%998244353
  p=x
print(ans%998244353)

Submission status: Wrong Answer

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


def ruijo(a, b, mod):
    for i in range(1000000):
        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

    for i in range(len(rui)):
        x *= (a ** rui[i]) % 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:
MOD = 998244353 
N = int(input())
D = [int(x) for x in input().split()]
lst = [0] * (N)
for d in D:
    lst[d] += 1
if (lst[0] != 1):
    print(0)
    exit()
first0 = False
for i in range(N):
    if (lst[i] != 0 and first0):
        print(0)
        exit()
    elif (lst[i] ==0):
        first0 = True
ans = 1
for i in range(N-1):
    ans *= pow(lst[i], lst[i+1], MOD)
print(ans)

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()
    if N == 1 and 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:
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:
        break
    if NUM[j-1] > 1:
        NUM[j] += 1
    if j == 1:
        NUM[j] +=1


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

result = count % 998244353
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

L = sorted(set(D))
s = 0

if (D[0] == 0) and (list(range(max(D) + 1)) == L):
    d = Counter(D)
    if 1 in d:
        s = 1
    for l in L[1:-1]:
        for i in range(d[l + 1]):
            s *= d[l]
            s %= 998244353
print(s)

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

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:
            if m[k-1]==2:
                num=num
            else:
                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:
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 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:
def f_b():
    n, *d = map(int, open(0).read().split())
    c = [0]*(max(d)+1)
    for i in range(n):
        c[d[i]] += 1

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

    print(a)

if __name__ == "__main__":
    f_b()

Submission status: Wrong Answer

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

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])
print(cur)

Submission status: Wrong Answer

Solution code:
from collections import Counter


M = 998244353
n = int(input())
d = sorted(map(int, input().split()))
counter = Counter(d)

ans = counter[0]
if ans != 0:
    for i in range(1, d[-1] + 1):
        if counter[i] == 0:
            ans = 0
            break
        if counter[i - 1] > 1:
            m, n = counter[i - 1], counter[i]
            c = m ** n
            ans *= c

print(ans % M)

Submission status: Wrong Answer

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

tree_list = [0] * (max_D+1)
for idx, d in enumerate(D):
    tree_list[d] += 1
count = 1
for idx, tree in enumerate(tree_list):
    if idx == 0:
        count *= tree
    else:
        if tree == 0:
            count = 0
        else:
            count *= tree_list[idx - 1]**tree
if len(tree_list) == 1:
    print(1)
else:
    print(count%998244353)

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 % mod
        tmp = cnt[i]
        ans = ans % mod
    print(ans % 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+1):
    y = counted[i]
    if y!= 0:
        result = result * pow(x,y) %998244353
        x = y
    else:
        print("0")
        exit()
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

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

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

print(ans % mod)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
c=[0 for i in range(max(d)+1)]
for x in d:
  c[x]+=1
p=1
for x in c:
  ans*=p**x
  p=x
print(ans%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)
    if ngflg:
        print("0")
    else:
        ans_ar= np.array([int(k) ** len(list(g)) for k, g in groupby(ar)])
        print(np.prod(ans_ar) % 998244353)

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

Submission status: Wrong Answer

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

INF = 998244353

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

if D.count(0) != 1:
    print(0)
    exit()

res = 1
pre = 1

for i in range(1,N):
    now = D.count(i)
    if now == 0:
        break
    res = (res * pre ** now) % INF
    pre = now % INF

print(res)

Submission status: Wrong Answer

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

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(d)>1 and d[-1]!=d[-2]:
  ans*=count
elif len(d)>1 and d[-1]==d[-2]:
  ans*=(count**acount)

if d[0]==0:
  print(ans%998244353)
elif d[0]!=0:
  print(0)

Submission status: Wrong Answer

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

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

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

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

print(ans)

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 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 % 998244353)

Submission status: Wrong Answer

Solution code:
mod = 998244353

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

dep = max(D)
dict = [0]*(dep+1)

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

Submission status: Wrong Answer

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

res = 1
for i in range(0, max(D_list)):
    if((D_list.count(i)!=0) and (D_list.count(i+1)!=0)):
        res *= D_list.count(i) ** D_list.count(i+1)
    else:
       res = 0
       break

print(res % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
box = [0 for x in range(max(li)+1)]
for i in li:
    box[i] += 1
count = 1

if len(box) > 2:
    for i in range(1, len(box)-1):
        count *= box[i] ** box[i+1]
else:
    count = 1
    
if box[0] != 1:
    count = 0

print(count % 998244353)

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

import numpy as np

def main():
    N = int(input())
    Ds = np.array([int(d) for d in input().split()])

    Ds.sort()
    if Ds[Ds==0].size != 1:
        print(0)
        return
    Ds = Ds[1:]

    l = 0
    r = 1
    c = []
    while Ds.size > 0:
        l = l + 1
        cnt = Ds[Ds==l].size
        c.append((r, cnt))
        r = cnt
        Ds = Ds[cnt:]
        
    ans = 1
    divider = 998244353
    for i, j in c:
        ans = (ans*(i**j))%divider
    
    print(ans)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",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(int(ans%998244353))

Submission status: Wrong Answer

Solution code:


def solve():
    N = int(input())
    D = [int(i) for i in input().split()]
    # 対象となる木のパターン数のチェック
    mD = max(D)
    nD = [0] * (mD + 1)
    for d in D:
        nD[d] += 1
    if nD[0] != 1:
        print(0)
        return
    count = nD[0]
    for i in range(2, len(nD)):
        count *= nD[i - 1] ** nD[i]
        count = count % 998244353
    print(count)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

sum = 1
if d[0] == 0 and d.count(0)==1:
  for i in range(1, n):
    sum *= int(d[i]) 
  print(sum)
else:
  print("0")

Submission status: Wrong Answer

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

d.sort()
dd=[0]*10**5
max=0
for i in d:
    dd[i]+=1
    if(max<i):
        max=i

ans=True
now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in range(1,max+1):
    if(dd[i]==0):
        ans=False
    now=now*(before**dd[i]) % 998244353
    before=dd[i]
    #print(dd[i],now)

if(ans):
    print(now)
else:
    print("0")

Submission status: Wrong Answer

Solution code:
from collections import Counter


M = 998244353
n = int(input())
d = sorted(map(int, input().split()))
counter = Counter(d)

ans = counter[0]
for i in range(1, d[-1] + 1):
    if counter[i] == 0:
        ans = 0
        break
    if counter[i - 1] > 1:
        m, n = counter[i - 1], counter[i]
        c = m ** n
        ans *= c


print(ans % M)

Submission status: Wrong Answer

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

d.sort()
dd=[0]*10**5
max=0
for i in d:
    dd[i]+=1
    if(max<i):
        max=i

ans=True
now=1
before=0
if(dd[0]!=1):
    ans=False
else:
    before=1

for i in range(1,max+1):
    if(dd[i]==0):
        ans=False
    now=now*(before**dd[i]) % 998244353
    before=dd[i]
    print(dd[i],now)

if(ans):
    print(now)
else:
    print("0")

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] or not dc[i+1]:
                count = 0
                break
            else:
                count = ((count % mod) * (dc[i]**dc[i+1] % mod)) % mod
        print(count % mod)


if __name__ == '__main__':
    main()

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.sort()
    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:
import collections

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

const = 998244353

c = collections.Counter(d)

m = max(d)

if c[0] != 1:
    print(0)
else:
    ans = 1
    for i in range(m):
        j = i + 1
        old = c[j - 1]
        new = c[j]
        if new == 0:
            ans = 0
            break
        else:
            a = pow(old, new) % const
            if a == 0:
                ans = 0
                break
            else:
                ans = (ans * a) % const

    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
d = list(map(int, input().split()))
for i in range(len(d)):
    if i == 0 and d[i] != 0:
        print(0)
        exit()
    if i != 0 and d[i] == 0:
        print(0)
        exit()

e = collections.Counter(d)

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:
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
k = [0]*100005
for i in d:
    k[i] += 1
c = 1
for i in range(d[-1]):
    for j in range(k[i+1]):
        c *= k[i]
        c %= 998244353
print(c)

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 *= pow(C[i], C[i+1], MOD) % MOD
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

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

div_num = 998244353
result = 1
ct_l = []

for i in range(n):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1

#print(ct_l)
prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    #print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v%div_num
    prev_v = curr_v
    #print(prev_v, curr_v, result)

if e < 0:
    print(0)
else:
    print(result)

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) % 998244353
    elif s[i] == deep + 1:
      c *= pow_k(a, b, 998244353) % 998244353
    else:
      c = 0
      break  
print(c)

Submission status: Wrong Answer

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

a = max(d)
ans = 1
if d.count(0) == 0:
    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:
from collections import Counter
import sys
input = sys.stdin.readline

_ = input()
d = list(map(int,input().split()))
d = sorted(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 i != 0 and d[i][1] == 1:
        cnt *= d[i-1][1]
    elif i != 0 and d[i][1] > 1:
        cnt *= d[i][1]**i-1
else:
    print(cnt%998244353)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
if D[0] == 0:
    A = collections.Counter(D)
    result = 1
    for i in range(max(D)):
        result *= A[i] ** A[i + 1]
    print(result % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
d = list(map(int, input().split()))
heapq.heapify(d)
if d[0] != 0:
    print(0)
else:
    pre = -1
    num = 0
    ans = 1
    for i in range(len(d)):
        if d[0] == 0:
            if i > 0:
                print(0)
                break
            else:
                pre = 0
                heapq.heappop(d)
                continue
        if d[0] == pre:
            num += 1
            if i == n-1:
                ans *= pre**num
            heapq.heappop(d)
        elif d[0] - pre > 1:
            print(0)
            break
        else:
            if i == 1:
                num = 1
                pre = d[0]
                heapq.heappop(d)
                continue
            ans *= pre**num
            pre = d[0]
            if i == n-1:
                ans *= pre
            num = 1
            heapq.heappop(d)
    else:
        print(ans)

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

INF = 998244353

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

if D.count(0) != 1:
    print(0)
    exit()

res = 1
pre = 1

for i in range(1,N):
    now = D.count(i)
    if now == 0:
        break
    res = (res * pre ** now) % INF
    pre = now

print(res)

Submission status: Wrong Answer

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

div_num = 998244353
result = 1
ct_l = []

for i in range(n):
    ct_l.append(0)

for item in l:
    ct_l[item] += 1

#print(ct_l)
prev_v = -1
curr_v = -1
e = n-1

for i, item in enumerate(ct_l):
    if i == 2:
        break
    if i == 0 and item == 1:
        pass
    else:
        e -= item
    if i == 1:
        prev_v = item

for i, item in enumerate(ct_l[2:]):
    #print(prev_v, item, e, result)
    e -= item
    if item == 0:
        break
    curr_v = item
    result *= prev_v**curr_v
    prev_v = curr_v
    #print(prev_v, curr_v, result)

if e < 0:
    print(0)
else:
    print(result%div_num)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

mydic = {}
myans = 0

for i in D:
    if i in mydic:
        mydic[i] += 1
    else:
        mydic[i] = 1

dicsorted = sorted(mydic.items())

myans = 1

if 0 not in mydic:
    print(0)
else:
    for i in range(len(dicsorted)):
        if i ==0:
            i = 1
        myans = myans * (i**dicsorted[i][1])
    print(myans)

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.sort()
    a = Counter(a)
    print (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)