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 collections import Counter
N, *D = map(int, open(0).read().split())

MOD = 998244353
ctr = Counter(D)
ans = 1
for i in range(1, max(ctr) + 1):
    ans = ans * ctr[i - 1] ** ctr[i] % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline()[:-1].decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

n=int(input())
D=list(map(int,input().split()))
ans=1
data=[0]*(10**5)
D.sort()
for i in range(n):
    data[D[i]]+=1
for i in range(1,n-1):
    ans*=data[i-1]**data[i]
if D[0]!=0:
    ans=0
if data[0]>=2:
    ans=0
print(ans)
# print(data[:20])

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
mx=d[-1]
count=[0]*(mx+1)
j=0
MOD=998244353
if d[0]!=0:
    print(0)
    sys.exit()
count[0]=1
j=1
for i in range(1,n):
    if d[i]==j:
        count[j]+=1
    elif d[i]==j+1:
        j+=1
        count[j]+=1
    else:
        print(0)
        sys.exit()
c=1
for i in range(1,mx+1):
    c*=pow(count[i-1],count[i],MOD)
    c%=MOD
print(c)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True


mo=998244353

n=I()
d=LI()
dp=[0]*(1+n)
ans=1
m=0

for i in d:
    dp[i]+=1
    m=max(i,m)

for i in range(m):
    pt=pow(dp[i],dp[i+1],mo)
    ans*=pt
    ans%=mo


print(ans%mo)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N = int(input())
D = list(map(int, input().split()))

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

div = 998244353

c = Counter(D)

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

print(res)

Submission status: Wrong Answer

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

MOD = 998244353

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

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

cur = 1
for i in range(1, N):
    if occ[i] != 0 and occ[i - 1] == 0:
        print(0)
        quit()
    for j in range(occ[i]):
        cur = (cur * occ[i - 1]) % MOD

print(cur)

Submission status: Wrong Answer

Solution code:
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re
import heapq


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    n = ii()
    d = li()

    if not  d[0] == 0:
        print(0)
        exit()
    else:
        cnt = [0 for i in range(n+1)]
        for i in d:
            cnt[i]+=1
        for i in range(1,n):
            if cnt[i-1] == 0 and (not cnt[i] ==0):
                print(0)
                exit()
        ans = 1
        for i in range(1,n):
            if cnt[i] == 0:
                break
            
            ans = (ans*(cnt[i-1]**cnt[i]))%998244353

        print(ans)


main()

Submission status: Wrong Answer

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

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

#print(count[:10])

ans = 1
inf = 998244353

for i in range(len(count)):
    if i == 0:
        pass
    else:
        tmp = pow(count[i-1], count[i], inf)
        ans *= tmp
        ans %= inf

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
from collections import Counter
# import math
MOD = 998244353

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n = getN()
    nums = getList()
    cnt = Counter(nums)
    items = sorted(cnt.items(), key=lambda x: x[0])
    # print(items)

    ans = 1
    prev = 1
    for i, item in enumerate(items):
        if i != item[0]:
            print(0)
            return
        if item[0] == 0 and item[1] != 1:
            print(0)
            return
        else:
            # a,b = max(item[1], prev), min(item[1], prev)
            ans *= (prev**item[1])
            prev = item[1]
            ans %= MOD


    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
maxD = 0
count = [0 for _ in range(N)]
for d in D:
    maxD = max(maxD,d)
    count[d] += 1
answer = 1
for i in range(maxD):
    x = count[i]
    y = count[i+1]
    answer *= pow(x,y,MOD)
    answer %= MOD
print(answer)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
d = list(Counter(d).items())
if d[0][0] != 0 or d[0][1] > 1:
    print(0)
    quit()

n = len(d)
ans = 1
for i in range(1,n):
    j,k = d[i]
    l,m = d[i-1]
    if j != l+1:
        print(0)
        quit()
    ans *= m**k
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
    sys.exit()
ans = 1
for i in range(1, n):
    x = d.count(i)
    y = d.count(i-1)

    if x == 0:
        break
    else:
        ans *= y**x

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline

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

if D[0]!=0:
	ans = 0
else:
	D = Counter(D)

	ans = 1
	for i in range(dmax):
		ans *= D[i]**D[i+1]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
MOD = 998244353


def main():
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        print(0)
    else:
        count = 1
        for i in range(1, N):
            count *= D[i]
            if count >= MOD:
                count -= MOD
        print(count)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *D = map(int, open(0).read().split())

MOD = 998244353
ctr = Counter(D)
ans = 1
for i in range(1, max(ctr) + 1):
    ans *= ctr[i - 1] ** ctr[i] % MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
import random  # randome is not available at Codeforces
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
#eps=10**(-10)
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True


mo=998244353

n=I()
d=LI()
dp=[0]*(1+n)
ans=1
m=0

for i in d:
    dp[i]+=1
    m=max(i,m)

for i in range(m):
    pt=pow(dp[i],dp[i+1],mo)
    ans*=pt


print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mod=998244353
from collections import Counter
dd=Counter(d)
d.sort()
a=dd[0]
for i in range(1,d[-1]+1):
  if not i in dd:a*=0
  else:a*=dd[i-1]**dd[i]
  a%=mod
print(a)

Submission status: Wrong Answer

Solution code:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 998244353

n = ri()
ls = ril()

counter = collections.Counter(ls)
if ls[0] > 0 or counter[0] > 1:
    print(0)
    exit()

res = 1
for i in range(2, max(counter.values()) + 1):
    res *= counter[i - 1]**counter[i]
    res %= MOD
print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

def main():
    N=int(input())
    DL=[int(x) for x in input().split()]
    DL.sort()
    if DL[0]!=0:
        return 0

    dic=collections.Counter(DL)
    if dic[0]!=1:
        return 0
    keys=dic.keys()
    result=1
    for i in range(1,max(keys)+1):
        result*=dic[i-1]**dic[i]

    return result


print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
a=[l.count(i) for i in range(m+1)]
s=1
for i in range(m):
  s=(s*(a[i]**a[i+1]))%998244353
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
L=[int(i) for i in input().split()]
A=[0 for i in range(n)]

for num in L:
    A[num]+=1

if A[0]!=1 or L[0]!=0:
    print(0)
else:
    ans=1
    for i in range(n-1):
        ans*=A[i]**A[i+1]
    print(ans)

Submission status: Wrong Answer

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

count = {}
for i in d:
    count.setdefault(i, 0)
    count[i] += 1
count2 = []
for i, j in count.items():
    count2.append([i, j])
count2.sort()
ans = 1
if count2[0][0] == 0 and count2[0][1] == 1:
    for i in range(len(count2) - 1):
        if count2[i + 1][0] - count2[i][0] == 1:
            temp = count2[i][1] ** count2[i + 1][1]
            ans *= temp
            ans %= mod
        else:
            ans = 0
            break
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0 or 0 in d[1:]:
    print(0)
    exit(0)
c = [0] * n
for x in d:
    c[x] += 1
t = 1
ans = 1
for i in range(n - 1):
    ans *= t ** c[i]
    t = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353

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

C = [0]*N

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

if C[0]==1:
    counter=1
    ans = 1
    for i in range(1,N):
        if C[i]==0 and counter<N:
            ans = 0
            break
        elif C[i]==0:
            break
        else:
            ans *= pow(C[i-1] ,C[i], mod)
            ans %= mod
            counter += C[i]
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
mod = 998244353

n = int(input())
ds = list(map(int, input().split()))
if ds[0] != 0:
    print(0)
    exit(0)
ds = ds[1:]
dd = defaultdict(int)
dmax = -1
for d in ds:
    if d <= 0:
        print(0)
        exit(0)
    dd[d] += 1
    dmax = max(d, dmax)

for d in range(1, dmax+1):
    if d not in dd:
        print(0)
        exit(0)

total = 1
dd[0] = 1
for d in range(1, dmax+1):
    total *= (dd[d-1] ** dd[d]) % mod
print(total)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict as dd
input = sys.stdin.readline

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

if d[0] > 0:
  print(0)
  exit(0)
e = dd(int)
for i in range(N):
  e[d[i]] += 1
res = 1
#print(e)
for k in range(1, max(e.keys()) + 1):
  res *= pow(e[k - 1], e[k], mod)
  #print(res)
print(res)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  if l[0]!=0 or l.count(0)!=1:
    return 0

  ans=1
  l.sort()
  a=[0]*100010
  a[0]=1
  for x in l[1:]:
    a[x]+=1
    ans*=a[x-1]

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
from collections import Counter
N, *D = map(int, open(0).read().split())

ctr = Counter(D)
ans = 1
for i in range(1, max(ctr) + 1):
    ans *= ctr[i - 1] ** ctr[i]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    from collections import Counter
    n = int(input())
    d = list(map(int, input().split()))
    mod = 998244353
    m=max(d)
    d = Counter(d)
    ans=1
    for i in range(1, m+1):
        ans = (ans * pow(d[i - 1], d[i], mod)) % mod
    print(ans)
main()

Submission status: Wrong Answer

Solution code:
from collections import Counter
MOD = 998244353
N = int(input())
Ds = list(map(int, input().split()))

ct = Counter(Ds)
M = max(ct)
ans = 1
last = 1
for i in range(M+1):
    ans *= last ** ct[i]
    last = ct[i]
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

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

ans = 1
if D[0] != 0:
    ans = 0
for i in range(1,N-1):
    ans *= pow(c[i],c[i+1],mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod = 998244353

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

c = Counter()
c[-1] += 1
ans = 1

for d in D:
    ans *= c[d-1]
    c[d] += 1
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
if d[0] != 0:
    print(0)
else:
    count = 1
    for i in d[1:]:
        count *= i
    print(count)

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    MOD = 998244353
    N, *d_l = map(int, open(0).read().split())
    ans = 0
    
    if d_l[0] != 0:
        print(0)
        sys.exit()
    
    ans = d_l[1]
    for i in range(2, N):
        ans *= d_l[i]
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math
import collections

N, = map(int, sys.stdin.readline().rstrip().split(" "))
Ds = list(map(int, sys.stdin.readline().rstrip().split(" ")))
Ds.sort()

if Ds.pop(0) != 0:
    print(0)
else:
    leaf_count = collections.defaultdict(int)
    leaf_count[0] = 1
    result = 1
    for D in Ds:
        if leaf_count[D - 1] == 0:
            result = 0
            break
        else:
            result *= leaf_count[D - 1]
            result %= 998244353
            leaf_count[D] += 1
    print(result)
exit(0)

Submission status: Wrong Answer

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

zero_id = []
for i in range(len(d)):
    if d[i] == 0:
        zero_id.append(i)
if zero_id == [0]:
    from collections import Counter
    c = Counter(d)
    keys = sorted(c.keys())

    ans = 1
    for i in range(len(keys) - 1):
        if i != 0:
            ans *= c[keys[i]] ** c[keys[i+1]]
    print(ans % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=998244353
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    C=[0]*100001
    D=list(map(int,input().split()))
    if(D[0]!=0):
        print(0)
        return
    for d in D:
        C[d]+=1
    for i in range(100000):
        if(C[i]==0 and C[i+1]!=0):
            print(0)
            return
    i=C.index(0)
    C=C[:i]
    ans=1
    for i in range(1,len(C)):
        ans*=C[i-1]**C[i]
        ans%=MOD
    print(ans)
resolve()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()

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

a.sort()

a = s(a)
count = 1
for i in range(1,len(a)):
    if a[i][0]-1 != a[i-1][0]:
        print(0)
        exit()
    count *= (pow(a[i-1][1],a[i][1]))%998244353  
    count %= 998244353
print(count)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353


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


X = defaultdict(int)
for d in D:
    X[d] += 1


ans = 1
for d in D:
    if d == 0:
        continue

    ans *= X[d - 1]
    ans %= MOD

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
D=[int(i) for i in input().split()]
mod=998244353
import collections
DD=collections.Counter(D)
d=max(D)
ans=1
if D[0]!=0:
  print(0)
else:
  if DD[0]>1:
    print(0)
  else:
    for i in range(1,d+1):
      if DD[i]==0:
        ans=0
      else:
        ans=(ans*(DD[i-1]**DD[i]))%mod
  print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
d=list(map(int,input().split()))
d.sort()
mx=d[-1]
count=[0]*(mx+1)
j=0
MOD=998244353
if d[0]!=0:
    print(0)
    sys.exit()
for i in range(n):
    if d[i]==j:
        count[j]+=1
    elif d[i]==j+1:
        j+=1
        count[j]+=1
    else:
        print(0)
        sys.exit()
c=1
for i in range(1,mx+1):
    c*=pow(count[i-1],count[i],MOD)
    c%=MOD
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]
count = [0]*N
max_n = 0
for elem in D:
    count[elem] += 1
    if elem > max_n:
        max_n=elem

ans=1
if count[0] == 1 and D[0] == 0:
    for i in range(1,max_n+1):
        ans = ans*((count[i-1])**count[i])
else:
    ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:

n = int(input())
A = list(map(int,input().split()))
mod = 998244353
ans = 1

def pow(x, y):
    m = x
    ans = 1
    while y != 0:
        if y % 2 == 1:
            ans = (ans * m) % mod
        m = (m*m)% mod
        y //= 2
    return ans

# print(pow(3,4))

if A[0] != 0:
    print(0)
else:
    B = [0] * (max(A)+1)
    for i in range(n):
        B[A[i]] += 1
    # print(B)
    for i in range(len(B)-1):
        ans = (ans * pow(B[i], B[i+1])) % mod
    print(ans)

Submission status: Wrong Answer

Solution code:

# mを法とするときのa^n
def modpow(a,n,m):
    res = 1
    t = a
    while n:
        if n%2:
            res = (res*t)%m
        t = (t*t)%m
        n //= 2
    return res

MOD = 998244353

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

memo = [0]*(max(D)+1)
for d in D:
    memo[d] += 1



cnt = 1
for a,b in zip(memo, memo[1:]):
    cnt *= modpow(a,b,MOD)
    cnt %= MOD

print(cnt)

Submission status: Wrong Answer

Solution code:
mod = 998244353
N = int(input())
ds = [0] * N
max_D = 0

for d in map(int, input().split()):
    ds[d] += 1
    max_D = max(max_D, d)
if ds[0] != 1:
    print(0)
    quit()

ans = 1
prev = 1
for d in range(1, max_D + 1):
    ans *= pow(ds[d-1], ds[d], mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
dlist=[int(i) for i in input().split()]
if dlist[0]!=0:
    print(0)
else:
    dlist=sorted(dlist)
    before=0
    kyolist=[0]
    dame=0
    for i in range(n):
        if dlist[i]==before:
            kyolist[-1]+=1
        elif dlist[i]==before+1:
            kyolist.append(1)
        else:
            dame=1
        before=dlist[i]
    #print(kyolist)
    if dame==1 or kyolist[0]!=1:
        print(0)
    else:
        if len(kyolist)<=2:
            print(1)
        else:
            answer=1
            for i in range(len(kyolist)-1):
                answer*=(kyolist[i]**kyolist[i+1])
            print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
Ds = list(map(int, input().split()))
Ns = [0]*N
for D in Ds:
  Ns[D] += 1
#print(Ns)
r = 1
p = 1
for n in Ns:
  #r = r*(p**n)%998244353
  for i in range(n):
    r = r*p%998244353
  p = n
print(r)

Submission status: Wrong Answer

Solution code:
from operator import itemgetter
from itertools import groupby
N = int(input())
D = list(map(int, input().split()))
mod = 998244353
ID = sorted(enumerate(D), key=itemgetter(1))
ans = 1
pn = 1
for i, (v, g) in enumerate(groupby(ID, key=itemgetter(1))):
    if i != v:
        ans = 0
    n = len(list(g))
    if i==0 and n!=1:
        ans = 0
    ans = (ans * pow(pn, n, mod)) % mod
    pn = n

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
d = list(Counter(d).items())
if d[0][0] != 0:
    print(0)
    quit()

n = len(d)
ans = 1
for i in range(1,n):
    j,k = d[i]
    l,m = d[i-1]
    if j != l+1:
        print(0)
        quit()
    ans *= m**k
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from numpy import array, prod
N = int(input())
Dlist = list(map(int, input().split()))
if Dlist[0] != 0:
    print(0)
else:
    print(prod(array(Dlist[1:])))

Submission status: Wrong Answer

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

zero_id = []
for i in range(len(d)):
    if d[i] == 0:
        zero_id.append(i)
if zero_id == [0]:
    from collections import Counter
    c = Counter(d)
    keys = sorted(c.keys())

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

Submission status: Wrong Answer

Solution code:
n=int(input())
p=1
for i in input().split():
    if int(i)>1:
        p*=int(i)
print(p%998244353)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())

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

D.sort()

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

ans = 0
for i in D:

    if i == 0 and ans == 0:
        lis[i] += 1
        ans += 1

    elif i == 0 and ans != 0:
        print (0)
        sys.exit()

    else:

        lis[i] += 1
        ans *= lis[i-1]
        ans %= 998244353

    
print (ans%998244353)

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()
cnt = collections.Counter(d)
total = 1
p = 1
for i in range(1, n):
    if p == 0 and cnt[i] > 0:
        print(0)
        exit()
    total *= pow(p, cnt[i], mod)
    total %= mod
    p = cnt[i]
print(total % mod)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
#第二回全国統一プログラミング王決定戦予選 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 998244353
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
d = LI()
d.sort()
d = list(Counter(d).items())
if d[0][0] != 0:
    print(0)
    quit()
n = len(d)
ans = 1
for i in range(1,n):
    j,k = d[i]
    l,m = d[i-1]
    ans *= m**k
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    a = lmi()
    if a[0] != 0:
        exit(0)

    a.sort()
    ma = max(a)
    if a[1] == 0:
        exit(0)
    ans = 1
    dp = [0] * N
    for x in a:
        dp[x] += 1
    for i in range(1, ma + 1):
        ans = ans * pow(dp[i - 1], dp[i], 998244353)
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

#print(count[:10])

ans = 1
inf = 998244353

for i in range(len(count)):
    if i == 0:
        pass
    else:
        tmp = pow(count[i-1], count[i], inf)
        ans *= tmp
        ans %= inf

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
d = list(map(int, input().split()))
max_d = max(d)
c = Counter(d)
mod = 998244353

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

ans = 1
prev = 1
for i in range(1, max_d + 1):
    if c[i] == 0:
        ans = 0
    ans = (ans * pow(prev, c[i], mod)) % mod
    prev = c[i]

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)
if c[0] == 1 :
    ret = 1
    for k in c.keys() :
        if k == 0 :
            continue
        
        ret = ret * pow(c[k-1], c[k], mod) % mod
    print(ret)
    
else :
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Ds = list(map(int, input().split()))

ct = Counter(Ds)
M = max(ct)
ans = 1
last = 1
for i in range(M+1):
    ans *= last ** ct[i]
    last = ct[i]
print(ans)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 998244353

def solve():
    n = I()
    d = LI()
    f = defaultdict(lambda : 0)
    for i in d:
        f[i] += 1
    m = max(d)
    ans = 1
    if f[0] != 1:
        print(0)
        return
    for i in range(m):
        ans *= pow(f[i],f[i+1],mod)
        ans %= mod
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()