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 = int(input())
D = list(map(int, input().split()))
D = Counter(D)
if 0 not in D.keys():
    print(0)
    exit()
if D[0] > 1:
    print(0)
    exit()
max_key = max(D.keys())
cnt = [0] * (max_key + 1)
for i in range(0, max_key + 1):
    cnt[i] = D[i]
ans = 1
for i in range(1, len(cnt)):
    ans *= cnt[i-1] ** cnt[i]
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
d = sorted(list(map(int, input().split())))
mod = 998244353
if d[0] != 0:
    print(0)
else:
    pre = d[0]
    ans = 1
    for i in d[1:]:
        ans *= i
        ans %= mod
    print(ans)

Submission status: Wrong Answer

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

if d[0] != 0:
    print(0)
else:
    pre = d[0]
    ans = 1
    for i in d[1:]:
        ans *= i
    print(ans)

Submission status: Wrong Answer

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

if d[0] != 0:
    print(0)
else:
    pre = d[0]
    ans, count0, count1 = 1, 1, 1
    for i in d[1:]:
        if pre == i:
            count1 += 1
        else:
            ans *= count0**count1 
            pre = i
            count0 = count1
            count1 = 1
    ans *= count0**count1
        
    print(ans)

Submission status: Wrong Answer

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

if d[0] != 0:
    print(0)
else:
    ans = 0
    pre = 0
    for i in set(d):
        b = d.count(i)
        if pre == 0:
            ans = b
            pre = b
        else:
            ans *= pre**b
            pre = b
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*
n=input()
a=dict(Counter(list(map(int,input().split()))))
mod=998244353
ans=1
for i in a:
  if i==0 and a[i]==1:continue
  elif i==0 and a[i]!=1:
    ans=0
    break
  ans*=pow(a.get(i-1,0),a[i],mod)
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import*
n=input()
a=dict(Counter(list(map(int,input().split()))))
mod=998244353
ans=1
for i in a:
  if i==0:continue
  ans*=pow(a.get(i-1,0),a[i],mod)
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

if d[0] != 0:
  print(0)
  exit()
dd = Counter(d)
ans = 1
for i in range(max(d)):
  ans *= dd[i+1]
  ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import sys

n=int(input())

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

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

lis=[0 for i in range(n)]

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

s=1

i=0
while i+1<=n-1 and lis[i+1]!=0:
    s=(s*pow(lis[i],lis[i+1],998244353))%998244353
    i+=1
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
    if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
        print(0)
        exit()
    l[d[i]]+=1
    mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
    ans *= t**l[i]
    t=l[i]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int( input() )
D = list ( int(x) for x in input().split() )

Ds = [ 0 for i in range( max(D) + 1 ) ]

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

ans = 1

if Ds[ 0 ] != 1:
    ans = 0
else:
    for i in range( 1 , max(D) + 1 ):
        ans *= Ds[ i-1 ] ** Ds[i]

        if ans == 0:
            break
print( ans )

Submission status: Wrong Answer

Solution code:
N = int( input() )
D = list ( int(x) for x in input().split() )

Ds = [ 0 for i in range( N ) ]

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

ans = 1

if Ds[ 0 ] != 1:
    ans = 0
else:
    for i in range( 1 , N ):
        ans *= Ds[ i-1 ] ** Ds[i]
        if ans == 0:
            break
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)
    exit()


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:
        if total!=N:
            print(0)
            exit()
        else:break
    total+=B[i]
    ans*=(B[i-1]**B[i])%mod

print(ans)

Submission status: Wrong Answer

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:
        if total!=N:
            print(0)
            exit()
        else:break
    total+=B[i]
    ans*=(B[i-1]**B[i])
    ans%=mod

print(ans)

Submission status: Wrong Answer

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:
        if total!=N:
            print(0)
            exit()
        else:break
    total+=B[i]
    ans*=(B[i-1]**B[i])%mod

print(ans)

Submission status: Wrong Answer

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
total=1
for i in range(1,N):
    if B[i]==0:break
    total+=B[i]
    ans*=(B[i-1]**B[i])%mod

if total==N:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

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

print(ans)

Submission status: Wrong Answer

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

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


B=[0]*N
for d in D:
    B[d]+=1
if B[0]!=1:
    print(0)
    exit()

ans=1
for i in range(1,N):
    if B[i]==0:break
    ans*=B[i-1]**B[i]

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
if D.pop(0) != 0:
  ans = 0
else:
  ans = 1
  num = 1
  before = 1
  after = 0
  for i in D:
    if i == num:
      after += 1
    elif i == num+1:
      ans = ans * (before**after) %998244353
      num += 1
      before = after
      after = 1
    else:
      ans = 0
  ans = ans * (before**after) %998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
if D.pop(0) != 0:
  ans = 0
else:
  ans = 1
  num = 1
  before = 1
  after = 0
  for i in D:
    if i == num:
      after += 1
    elif i == num+1:
      ans *= before**after
      num += 1
      before = after
      after = 1
    else:
      ans = 0
  ans *= before**after
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
D.sort()
if D.pop(0) != 0:
  ans = 0
else:
  ans = 1
  num = 1
  before = 1
  after = 0
  for i in D:
    if i == num:
      after += 1
    elif i == num+1:
      ans *= before**after
      num += 1
      before = after
      after = 1
    else:
      ans = 0
  ans *= before**after
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = sorted(list(map(int, input().split())))
d_set = list(set(D))
MOD = 998244353

from collections import Counter
c = Counter(D)
res = 1
for k, v in c.items():
    if k == 0: continue
    res *= pow(k, v)
    res %= MOD

bl = True
if d_set[0] != 0:
    bl = False
for i in range(1, len(d_set)):
    if d_set[i] - d_set[i - 1] != 1:
        bl = False

print(res) if bl else print(0)

Submission status: Wrong Answer

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

ans = 1 if d[0]==0 else 0
for i in range(1,len(dep)):
  if dep[i]==0:
    ans = 0
    break
  ans *= (dep[i-1]%p) ** dep[i] % p
  ans %= p

print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
num = A[0] == 0
if num:
    # print(len(C))
    if C[0] == 1:
        for i in range(len(A)):
            if not C.get(i+1):
                if i < len(C)-1:num = 0
                break
            num = (num*pow(C[i],C[i+1],998244353))%998244353
            # print(num)

print(num%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
from collections import Counter
C = Counter(A)
num = A[0] == 0
if num:
    # print(len(C))
    if C[0] == 1:
        for i in range(len(A)):
            if not C.get(i+1):
                if i < len(C)-1:num = 0
                break
            num *= pow(C[i],C[i+1],998244353)
            # print(num)

print(num%998244353)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

input = sys.stdin.readline
P = 998244353


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

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

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

    max_depth = max(count.keys())
    ans = 1
    for d in range(max_depth):
        ans = (ans * pow(count[d], count[d + 1], mod=P)) % P

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict

input = sys.stdin.readline
P = 998244353


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

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

    max_depth = max(count.keys())
    ans = 1
    for d in range(max_depth):
        ans = (ans * pow(count[d], count[d + 1], mod=P)) % P

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = LIST()
mod = 998244353

ans = 1
i = 0
j = 0
p = 0.5
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if c > p*2 or (j == 0 and c == 0):
        print(0)
        exit()
    else:
        if j > 0:
            ans *= p**c
            ans %= 998244353
        p = c
        c = 0
        j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

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

c = Counter(d)
counts = [0]*(d[-1]+1)
for k, v in c.items():
    counts[k] = v
if counts[0] > 1:
    print(0)
    exit()
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i])
    ans %= 998244353
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

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

ans = 1
i = 0
j = 0
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if j == 0 and c > 1:
        print(0)
        exit()
    if j > 0:
        ans *= p**c % 998244353
    p = c
    c = 0
    j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

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

ans = 1
i = 0
j = 0
p = 0
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if j > 0:
        if c > p*2:
            print(0)
            exit()
        else:
            ans *= p**c % 998244353
    p = c
    c = 0
    j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

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

ans = 1
i = 0
j = 0
p = 0
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if j > 0:
        if c > p*2:
            print(0)
            exit()
        else:
            ans *= p**c % 998244353
    p = c
    c = 0
    j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

ans = 1
i = 0
j = 0
p = 0.5
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if c > p*2 or (j == 0 and c == 0):
        print(0)
        exit()
    else:
        if j > 0:
            ans *= p**c % 998244353
        p = c
        c = 0
        j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
d = sorted(LIST())

ans = 1
i = 0
j = 0
p = 0.5
c = 0
while i < n:
    while i < n and d[i] == j:
        c += 1
        i += 1
    if c > p*2:
        print(0)
        exit()
    else:
        if j > 0:
            ans *= p**c % 998244353
        p = c
        c = 0
        j += 1
 
print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
counts = [0] * (max(d)+1)
for k, v in c.items():
    counts[k] = v
if counts[0] > 1:
    print(0)
    exit(0)
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i], mod)
    # ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])
counts = [0] * (max(d)+1)
for k, v in s_c:
    counts[k] = v
if 0 in counts[:-1]:
    print(0)
    exit(0)
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i])
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])
counts = [0] * (max(d)+1)
for k, v in s_c:
    counts[k] = v
if 0 in counts[:-1]:
    print(0)
    exit(0)
ans = 1
for i in range(1, len(counts)):
    ans = pow(counts[i-1], counts[i])
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])
counts = [0] * (max(d)+1)
for k, v in s_c:
    counts[k] = v
if 0 in counts:
    print(0)
    exit(0)
ans = 1
for i in range(1, len(counts)):
    ans *= pow(counts[i-1], counts[i], mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit(0)

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])
counts = [0] * (max(d)+1)
for k, v in s_c:
    counts[k] = v

ans = 1
for i in range(1, len(counts)):
    # counts[i] = 0 があった場合 答えは 必ず 0 になる
    ans *= pow(counts[i-1], counts[i], mod)
    # ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit()

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])

ans = 1
for i in range(1, len(s_c)):
    ans *= pow(s_c[i-1][1], s_c[i][1], mod)
    ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import collections
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit()

# 頂点 i に隣接する頂点のうち、頂点 1 に近い頂点を pi とすると
# d_pi = d_i - 1 となる
# 各 i (i >= 2) について上の条件を満たす pi の個数の総乗を求める
c = Counter(d)
s_c = sorted(c.items(), key=lambda x: x[0])

ans = 1
for i in range(1, len(s_c)):
    ans *= pow(s_c[i-1][1], s_c[i][1], mod)

print(ans)

Submission status: Wrong Answer

Solution code:
# 7
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
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 S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
d = LI()
mod = 998244353
if d[0] != 0:
    print(0)
    exit()

s_d = sorted(d)
c = Counter(d)

# それぞれの頂点ごとに条件を満たすか計算、満たせば答えは di の総乗
is_ok = True
for elem in s_d:
    try:
        c[elem]
    except KeyError:
        is_ok = False
        break

if is_ok:
    ans = 1
    for elem in d[1:]:
        ans = (ans * elem) % mod
else:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
d = list(map(int, input().split()))
M = 998244353
from collections import Counter
c = Counter(d)
if d[0]!=0 or c[0]>=2:
    ans = 0
else:
    m = max(c.keys())
    ans = 1
    for i in range(1,m+1):
        if i not in c:
            ans = 0
            break
        ans *= pow(c[i-1], c[i], M)
print(ans)

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

MOD = 998244353

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

c = Counter(D)

ans = 1 * (not D[0]) * (c[0] == 1)
for i in range(1, max(c.keys())+1):
    ans *= pow(c[i-1], c[i], MOD)

print(ans)

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353
MOD = 998244353

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

c = Counter(D)

ans = 1 * (not D[0])
for i in range(1, max(c.keys())+1):
    ans *= pow(c[i-1], c[i], MOD)
    ans %= MOD

print(ans)

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353

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

c = Counter(D)

bef = 1
ret = 1 * (not D[0])

for i in range(len(c)):
    if c[i] == 0:
        ret = 0
    ret *= bef ** c[i]
    ret = ans(ret)
    bef = c[i]

print(ret)

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353

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

c = Counter(D)

bef = 1
ret = 1 * (not D[0])

for i in range(len(c)):
    if c[i] == 0:
        ret = 0
    ret *= bef ** c[i]
    bef = c[i]

print(ret)

Submission status: Wrong Answer

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

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353

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

c = Counter(D)

bef = 1
ret = 1 * (not D[0])

for i in range(len(c)):
    if c[i] == 0:
        ret = 0
    ret *= bef ** c[i]
    bef = c[i]

print(ret % 998244353)