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:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = IL()
M = max(A)
dic = DD(int)
for a in A:
  dic[a] += 1
if dic[0] != 1:
  print(-1)
  exit()
else:
  ans = 1
  for i in range(M):
    ans *= pow(dic[i],dic[i+1])
print(ans)

Submission status: Wrong Answer

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

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

max_d = max(d)
cnt = [0] * (max_d + 1)

for num in d:
    cnt[num] += 1

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

ans = 1

for i in range(1, len(cnt)):
    if cnt[i - 1] == 0:
        ans = 0
        break
    else:
        ans *= pow(cnt[i - 1], cnt[i], mod)
        ans %= mod

print(ans)

Submission status: Wrong Answer

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

from collections import Counter

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

    if D[0]!=0:
        print(0)
    else:
        mx = max(D)
        mod = 998244353
        ret = 1
        for i in range(1, mx+1):
            ret *= pow(Dc.get(i-1,0), Dc.get(i,0), mod)
            ret %= mod
        print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter

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

    if D[0]!=0:
        print(0)
    else:
        mx = max(D)
        D = Counter(D)
        mod = 998244353
        ret = 1
        for i in range(1, mx+1):
            ret *= pow(D.get(i-1,0), D.get(i,0), mod)
            ret %= mod
        print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

from collections import Counter

def main():
    N = int(input())
    D = list(map(int, input().split()))
    mx = max(D)
    D = Counter(D)
    mod = 998244353

    if D[0]!=1:
        print(0)
    else:
        ret = 1
        for i in range(1, mx+1):
            ret *= pow(D.get(i-1,0), D.get(i,0), mod)
            ret %= mod
        print(ret)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if D[0] != 0:
    print(0)
else:
    prev = 1
    ans = 1
    for i in range(1, max(D) + 1):
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if cnt_D.get(0, 0) != 1:
    print(0)
else:
    prev = 1
    ans = 1
    for i in range(1, max(D) + 1):
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
cnt_D = Counter(D)
if cnt_D.get(0, 0) != 1:
    print(0)
else:
    prev = cnt_D.get(1, 0)
    ans = 1
    for i in range(2, max(D) + 1):
        if prev == 0:
            ans = 0
            break
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
max_D = max(D)
cnt_D = Counter(D)
if cnt_D.pop(0, 0) != 1:
    print(0)
else:
    prev = cnt_D.pop(1, 0)
    ans = 1
    for i in range(2, max_D + 1):
        if prev == 0:
            ans = 0
            break
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
max_D = max(D)
cnt_D = Counter(D)
if D[0] != 0:
    print(0)
else:
    prev = cnt_D.pop(1, 0)
    ans = 1
    for i in range(2, max_D + 1):
        if prev == 0:
            ans = 0
            break
        v = cnt_D.get(i, 0)
        ans *= pow(prev, v, MOD)
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


MOD = 998244353
N = int(input())
D = list(map(int, input().split()))
max_D = max(D)
cnt_D = Counter(D)
if D[0] != 0:
    print(0)
else:
    prev = cnt_D.pop(1)
    ans = 1
    for i in range(2, max_D + 1):
        v = cnt_D.get(i, 0)
        if v == 0:
            ans = 0
            break
        ans *= prev ** v
        ans %= MOD
        prev = v
    print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    D = list(map(int, input().split()))
    p = 998244353
    l = Counter(D)
    if l[0] != 1:
        print(0)
        exit()
    ans = 1
    for i in range(1,max(l)+1):
        if not l[i]:
            exit(print(0))
        ans *= pow(l[i-1],l[i],p)
        ans %= p
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    D = list(map(int, input().split()))
    p = 998244353
    l = Counter(D)
    if l[0] != 1:
        print(0)
        exit()
    ans = 1
    for i in range(1,max(l)+1):
        if l[i] == 0:
            exit(print(0))
        else:
            ans *= pow(l[i-1],l[i],p)
            ans %= p
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    D = list(map(int, input().split()))
    p = 998244353
    l = Counter(D)
    if l[0] != 1:
        print(0)
        exit()
    ans = 1
    flag = False
    for i in range(1,len(l)):
        if l[i] == 0:
            flag = True
            break
        else:
            ans *= pow(l[i-1],l[i],p)
            ans %= p
    if flag:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    D = list(map(int, input().split()))
    p = 998244353
    l = Counter(D)
    ans = 1
    flag = False
    for i in range(len(l)):
        if l[i] == 0:
            flag = True
            break
        elif i > 0:
            ans *= pow(l[i-1],l[i],p)
            ans %= p
    if flag:
        print(0)
    else:
        print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if d[0]!=0:
  print(0)
  exit(0)
  
m=max(d)
counts=[0]*(m+1)

import collections
counter=collections.Counter(d)
if counts[0]!=1:
  print(0)
  exit(0)
for key,val in counter.items():
  counts[key]=val
  
ans=1
div=998244353
for i in range(1,len(counts)):
  ans*=pow(counts[i-1],counts[i],div)
  ans%=div
  
print(ans)

Submission status: Wrong Answer

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

if d[0]!=0:
  print(0)
  exit(0)
  
m=max(d)
counts=[0]*(m+1)

import collections
counter=collections.Counter(d)
for key,val in counter.items():
  if key==0 and val>1:
    print(0)
    exit(0)
  counts[key]=val

Submission status: Wrong Answer

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

if d[0]!=0:
  print(0)
  exit(0)
  
m=max(d)
counts=[0]*(m+1)

import collections
counter=collections.Counter(d)
for key,val in counter.items():
  counts[key]=val
  
ans=1
div=998244353
for i in range(1,len(counts)):
  ans*=pow(counts[i-1],counts[i],div)
  ans%=div
  
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
dl = list(map(int,input().split()))
if dl[0] != 0:
  print(0)
  exit()
d_dic = dict()
for d in dl:
  if d in d_dic:
    d_dic[d] += 1
  else:
    d_dic[d] = 1
l = max(d_dic.keys())
for i in range(l):
  if not i in d_dic:
    print(0)
    exit()
ans = 1
for i in range(l):
  ans *= d_dic[i]**d_dic[i+1]
  ans = ans%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
N = int(sys.stdin.readline().rstrip())
D = list(map(int, sys.stdin.readline().rstrip().split()))
mod = 998244353

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

d_cnt = sorted(Counter(D).items())

for k, v in d_cnt:
    if k == 0:
        if v > 1:
            print(0)
            exit()
        else:
            ans = v
            par = v
    else:
        ans *= pow(par, v, mod)
        ans %= mod
        par = v
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
D=list(map(int, input().split() ))
d=dict(Counter(D))
p=998244353
#print(d)

ans=1
if 0 not in d:
  print(0)
else:
  if d[0]!=1:
    print(0)
  else:
    for num in d:
      if num==0:
        pass
      else:
        if num-1 in d:
          s= ((d[num-1])**d[num])%p
          ans = (ans * s)%p
        else:
          print(0)
          exit()
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

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

if n==1 and arr[0]==0:
    print(1)
    exit()


chk=True

p=Counter(arr)

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

tmp=0
for i in range(1,max(list(p))+1):
    if p[i]>0:
        pass
    else:
        print(0)
        exit()

ans=1

#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    
    ans=(ans*pow(p[i], p[i+1], mod)) %mod
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

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

if n==1 and arr[0]==0:
    print(1)
    exit()


chk=True

p=Counter(arr)

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

tmp=0
for i in range(1,max(list(p))+1):
    if p[i]>0:
        pass
    else:
        print(0)
        exit()

ans=1

#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,q)
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

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

if n==1 and arr[0]==0:
    print(1)
    exit()


chk=True

p=Counter(arr)
tmp=0
for i in range(1,max(list(p))+1):
    if p[i]>0:
        pass
    else:
        print(0)
        exit()

ans=1
if p[0]>1:
    print(0)
    exit()
#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,q)
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

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

if n==1 and arr[0]==0:
    print(1)
    exit()


chk=True

p=Counter(arr)
tmp=0
for i in sorted(list(p)):
    if i==tmp:
        pass
    elif i==tmp+1:
        tmp=i
    else:
        print(0)
        exit()

ans=1
if p[0]>1:
    print(0)
    exit()
#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,q)
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

if n==1 and arr[0]==0:
    print(1)
    exit()
elif n==1 and arr[0]!=0:
    print(0)
    exit()

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

chk=True

p=Counter(arr)
tmp=0
for i in sorted(list(p)):
    if i==tmp:
        pass
    elif i==tmp+1:
        tmp=i
    else:
        print(0)
        exit()

ans=1
if p[0]>1:
    print(0)
    exit()
#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    #q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,p[i]**p[i+1])
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

if n==1 and arr[0]==0:
    print(1)
    exit()
elif n==1 and arr[0]!=0:
    print(0)
    exit()

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

chk=True

p=Counter(arr)
tmp=0
for i in sorted(list(p)):
    if i==tmp:
        pass
    elif i==tmp+1:
        tmp=i
    else:
        print(0)
        exit()

ans=1

#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    #q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,p[i]**p[i+1])
    
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

if n==1 and arr[0]==0:
    print(1)
    exit()
elif n==1 and arr[0]!=0:
    print(0)
    exit()

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

chk=True

p=Counter(arr)
tmp=0
for i in sorted(list(p)):
    if i==tmp:
        pass
    elif i==tmp+1:
        tmp=i
    else:
        print(0)
        exit()

ans=1

#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    #q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,p[i]**p[i+1])
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
mod=998244353
n=ii()
arr=limii()

if n==1 and arr[0]==0:
    print(1)
    exit()
elif n==1 and arr[0]!=0:
    print(0)
    exit()

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

chk=True

p=Counter(arr)
tmp=0
for i in sorted(list(p)):
    if i==tmp:
        pass
    elif i==tmp+1:
        tmp=i
    else:
        print(0)
        exit()

ans=1

#掛け算の場合
# (a*b)%mod と同等
def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

#割り算の場合
# (a//b)%mod と同等
def div(a,b):
    return a*pow(b, mod-2, mod)

#累乗の場合
#a**n %p と同等
def p_f(a,n,pp):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %pp
        if bi[i]=="1":
            res=(res*a) %pp
    return res

for i in range(max(p.values())):
    q=p_f(p[i],p[i+1],998244353)
    ans=mul(ans,q)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
import collections
l=list(map(int,input().split()))
cnt=collections.Counter(l)
if cnt[0] > 1 or l[0] != 0:
   print(0)
   exit()
ans=1
mod=998244353
for i in range(1,max(cnt)):
   ans*=pow(i,cnt[i],mod)
   ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
import collections
l=list(map(int,input().split()))
cnt=collections.Counter(l)
if cnt[0] > 1 or l[0] != 0:
   print(0)
   exit()
ans=1
mod=998244353
for i in range(1,max(cnt)+1):
   ans*=pow(i,cnt[i],mod)
   ans%=mod
print(ans)

Submission status: Wrong Answer

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

node = [0]*(max(d)+1)
ans = 1

for i in range(n):
	node[d[i]] += 1

if d[0] == 0 and 0 not in node[1:]:
	for i in range(2,len(node)):
		a = node[i-1]**node[i]
		ans *= a
		ans %= 998244353
else:
	ans = 0

print(ans)

Submission status: Wrong Answer

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

node = [0]*(max(d)+1)
ans = 1

for i in range(n):
	node[d[i]] += 1

if d[0] == 0 and 0 not in node[1:]:
	for i in range(2,len(node)):
		a = (node[i-1]**node[i])%998244353
		ans *= a
		ans %= 998244353
else:
	ans = 0

print(ans)