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:
#! /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 bef == 0:
        ret = 0
    ret *= bef ** c[i]
    bef = c[i]

print(ret % 998244353)

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 bef == 0 or bef + 1 != c[i]:
        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 bef == 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)):
    ret *= bef ** c[i]
    ret = ans(ret)
    bef = c[i]

print(ret)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

MOD = 998244353

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

if p[0] == 1 and D[0] != 0:
    ans = 1
    for i in range(N + 1):
        ans *= p[i] ** p[i + 1]
        ans %= MOD

    print(ans % MOD)

else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

MOD = 998244353

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

if p[0] == 1:
    ans = 1
    for i in range(max(D), 0, -1):
        ans *= pow(p[i - 1], p[i], mod=MOD)

    print(ans % MOD)

else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

MOD = 998244353

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

ans = 1
for i in range(max(D), 0, -1):
    ans *= pow(p[i - 1], p[i], mod=MOD)

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

MOD = 998244353

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

ans = 1
for i in range(max(D), 0, -1):
    ans *= p[i - 1] ** p[i]
    ans %= MOD

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

N = int(input())
D = list(map(int, input().split()))
dmax = max(D)
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
    cnt[d] += 1

if cnt[0] != 1:
    print(0)
    exit()
ans = cnt[0]
for i in range(1, dmax + 1):
    if cnt[i] == 0:
        print(0)
        exit()
    now = my_pow(cnt[i - 1], cnt[i], MOD)
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
dmax = max(D)
for d in D:
    cnt[d] += 1

if cnt[0] != 1:
    print(0)
    exit()
ans = cnt[0]
for i in range(1, dmax + 1):
    now = my_pow(cnt[i - 1], cnt[i], MOD)
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
def my_pow(base, n, mod):
    if n == 0:
        return 1
    x = base
    y = 1
    while n > 1:
        if n % 2 == 0:
            x *= x
            n //= 2
        else:
            y *= x
            n -= 1
        x %= mod
        y %= mod
    return x * y % mod

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
dmax = max(D)
for d in D:
    cnt[d] += 1

ans = cnt[0]
for i in range(1, dmax + 1):
    now = my_pow(cnt[i - 1], cnt[i], MOD)
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
dmax = max(D)
for d in D:
    cnt[d] += 1

ans = cnt[0]
for i in range(1, dmax + 1):
    now = cnt[i - 1] ** cnt[i]
    now %= MOD
    ans *= now
    ans %= MOD
print(ans % MOD)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
dmax = max(D)
for d in D:
    cnt[d] += 1

ans = cnt[0]
for i in range(1, dmax + 1):
    if cnt[i] == 0:
        ans = 0
        break
    now = cnt[i - 1] ** cnt[i]
    now %= MOD
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353
cnt = [0] * (10 ** 5 + 1)
for d in D:
    cnt[d] += 1
ans = cnt[0]
for i in range(1, 10 ** 5 + 1):
    now = cnt[i - 1] ** cnt[i]
    now %= MOD
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

cnt = [0] * (N)
for d in D:
    cnt[d] += 1
ans = cnt[0]
for i in range(1, N):
    now = cnt[i - 1] ** cnt[i]
    now %= MOD
    ans *= now
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
dic = Counter(A)
num = 1
n = 0
if (A[0]!=0)|(dic.get(1)==None):num = 0
else:
    while 1:
        # num *= dic[n]**dic[n+1]%998244353
        num *= pow(dic[n],dic[n+1],998244353)
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
dic = Counter(A)
num = 1
n = 0
if (A[0]!=0)|(dic.get(1)==None):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]%998244353
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
# print(dic)
num = 1
n = 0
if (dic.get(0)==None)|(dic.get(1)==None):num = 0
elif(dic[0]>1):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]%998244353
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
# print(dic)
num = 1
n = 0
if (dic.get(0)==None)|(dic.get(1)==None):num = 0
elif(dic[0]>1):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
# print(dic)
num = 1
n = 0
if not dic.get(0):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
print(dic)
num = 1
n = 0
if not dic.get(0):num = 0
else:
    while 1:
        num *= dic[n]**dic[n+1]
        dic.pop(n)
        n += 1
        if not dic.get(n+1):
            dic.pop(n)
            if dic.keys():
                num = 0
            break
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N):
    if A[i] in dic:dic[A[i]] += 1
    else:dic[A[i]] = 1
# print(dic)
num = 1
n = 0
while dic.get(n+1):
    if not dic.get(0):
        num = 0
        break
    num *= dic[n]**dic[n+1]
    n += 1

print(num)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter

n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(len(c)):
    if i != c[i][0]:
        ans = 0
        break
    ans *= c[i - 1][1]**c[i][1]
    ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter

n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = [(0, 1)] + sorted(c.items())
ans = d[0] == 0
for i in range(len(c)):
    if i != c[i][0]:
        ans = 0
        break
    ans *= c[i - 1][1]**c[i][1]
print(ans)

Submission status: Wrong Answer

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

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

A = collections.Counter(D)
A = list(A.items())
A.sort()

if len(A) != max(D) + 1:
    print(0)
    exit()

ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
    if ans >= 998244353:
        ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import Counter

n, *d = map(int, open(0).read().split())
c = Counter(d[1:])
c = sorted(c.items())
ans = d[0] == 0
for i in range(len(c)):
    if i != c[i][0] - 1:
        ans = 0
        break
    ans *= c[i - 1][1]**c[i][1]
print(ans)

Submission status: Wrong Answer

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

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

for i in range(max(D)):
    if i not in D:
        print(0)
        exit()

A = collections.Counter(D)
A = list(A.items())
A.sort()
ans = 1
for i in range(max(D)):
    ans *= A[i][1]**A[i+1][1]
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()
counter = Counter(D)
counter = sorted(counter.items())
# print(counter)
keys = []
values = []
for i in range(len(counter)):
  keys.append(counter[i][0])
  values.append(counter[i][1])
for i in range(len(keys)):
  if i != keys[i]:
    print('0')
    exit()
ans = 1
for i in range(1, len(counter) - 1):
  ans *= pow(values[i], values[i + 1], mod)
  ans %= mod
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:
  print('0')
  exit()
counter = Counter(D)
counter = sorted(counter.items())
# print(counter)
keys = []
values = []
for i in range(len(counter)):
  keys.append(counter[i][0])
  values.append(counter[i][1])
for i in range(len(keys)):
  if i != keys[i]:
    print('0')
    exit()
ans = 1
for i in range(1, len(counter) - 1):
  ans *= values[i] ** values[i + 1]
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    if D[0]!=0 or node_cnt[0]!=1:
        print(0);exit()
    
    ans = 1
    pre = 1
    for k,v in sorted(node_cnt.items()):
        ans*=pow(pre,v)
        ans%=mod
        pre = v
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    if D[0]!=0 or node_cnt[0]!=1:
        print(0);exit()
    
    ans = 1
    pre = 1
    for k,v in sorted(node_cnt.items()):
        ans*=pow(pre,v,mod)
        pre = v
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    if D[0]!=0 or node_cnt[0]!=1:
        print(0);exit()
    
    ans = 1
    max_depth = max(D)

    for i in range(max_depth):
        # if i not in node_cnt:
            # print(0);exit()
        # else:
        ans*=pow(node_cnt[i],node_cnt[i+1],mod)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))
    mod = 998244353

    from collections import Counter

    node_cnt = Counter(D)
    if D[0]!=0 or node_cnt[0]!=1:
        print(0);exit()
    
    ans = 1
    max_depth = max(D)

    for i in range(max_depth):
        if i not in node_cnt:
            print(0);exit()
        else:
            ans*=pow(node_cnt[i],node_cnt[i+1],mod)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    D = list(map(int,input().split()))

    from collections import Counter

    node_cnt = Counter(D)
    if D[0]!=0 or node_cnt[0]!=1:
        print(0);exit()
    
    ans = 1
    max_depth = max(D)

    for i in range(max_depth):
        if i not in node_cnt:
            print(0);exit()
        else:
            ans*=node_cnt[i]**node_cnt[i+1]
    print(ans)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
c = collections.Counter(d)
if c[0] != 1:
    ans = 0
if c[1] == 0:
    ans = 0
x = 1
for i in range(1,max(d)+1):
    if c[i] == 0:
        ans = 0
        break
    ans *= pow(c[i-1],c[i],mod)
    x += c[i]
    ans %= mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
c = collections.Counter(d)
if c[0] != 1:
    ans = 0
if c[1] == 0:
    ans = 0
x = 1
for i in range(1,n):
    if x == n:
        break
    if c[i] == 0:
        ans = 0
        break
    ans *= pow(c[i-1],c[i],mod)
    x += c[i]
    ans %= mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
c = collections.Counter(d)
if c[0] != 1:
    ans = 0
if c[1] == 0:
    ans = 0
x = 1
for i in range(1,n):
    if x == n:
        break
    ans *= pow(c[i-1],c[i],mod)
    x += c[i]
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

ans = 1
c = collections.Counter(d)
if c[0] != 1:
    ans = 0
x = 1
for i in range(1,n):
    if x == n:
        break
    ans *= pow(c[i-1],c[i],mod)
    x += c[i]
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[4]:


import collections


# In[2]:


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


# In[5]:


sorted(collections.Counter(D[1:]).items(), key=lambda x:x[0])


# In[6]:


if D[0] == 0:
    ans = 1
    tmp = 1
    cnt = 0
    for i,x in sorted(collections.Counter(D[1:]).items(), key=lambda x:x[0]):
        if i == cnt+1:
            ans *= tmp**x
            tmp = x
            cnt += 1
        else:
            ans = 0
            break
    print(ans)
else:
    print(0)


# In[ ]:

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
dic=Counter(d)
l=sorted(dic.items())
if l[0]!=(0,1):
    print(0)
    exit()
MOD=998244353
ans=1
for i in range(1,len(l)):
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n=int(input())
d=list(map(int,input().split()))
dic=Counter(d)
l=sorted(dic.items())
if d[0]!=0 or l[0][1]!=1:
    print(0)
    exit()
MOD=998244353
ans=1
for i in range(1,len(l)):
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
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:
    print(0)
    exit()
dic=Counter(d)
l=sorted(dic.items())
if l[-1][0]!=len(l)-1:
    print(0)
    exit()
MOD=998244353
ans=1
for i in range(1,len(l)):
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dic=Counter(d)
l=sorted(dic.items())
if l[-1][0]!=len(l)-1:
    print(0)
    exit()
MOD=998244353
ans=1
for i in range(1,len(l)):
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dic=Counter(d)
l=sorted(dic.items())
if l[-1][0]!=len(l)-1:
    print(0)
    exit()
MOD=9982244353
ans=1
for i in range(1,len(l)):
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

dic=Counter(d)
l=sorted(dic.items())
MOD=9982244353
ans=1
for i in range(1,len(l)):
    if l[i][0]!=i:
        print(0)
        exit()
    temp=pow(l[i-1][1],l[i][1],MOD)
    ans=ans*temp%MOD
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)
# 0が1つでない場合の答えは0になる
if c[0] != 1:
    print(0)
    exit(0)

MOD = 998244353
cnt = 1
for i in range(1, max(D)+1):
    cnt *= pow(c[i-1], c[i], MOD)
print(cnt % MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)
# 0が1つでない場合の答えは0になる
if c[0] != 1:
    print(0)
    exit(0)

MOD = 998244353
cnt = 1
for i in range(1, max(D)+1):
    cnt *= pow(c[i-1], c[i], MOD)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)
# 0が1つでない場合の答えは0になる
if c[0] != 1:
    print(0)
    exit(0)

MOD = 998244353
cnt = 1
for i in range(1, max(D)+1):
    cnt *= pow(c[i-1], c[i],)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)
# 0が1つでない場合の答えは0になる
if c[0] != 1:
    print(0)
    exit(0)

# N = 1の時は1
if N == 1:
    print(1)
    exit(0)

# 親の数*子の数を求める
parent = c[0]
ans = c[0]
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)

# N = 1の時は1
if N == 1:
    print(1)
    exit(0)

# 親の数*子の数を求める
parent = c[0]
ans = c[0]
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)

# N = 1の時は1
if N == 1:
    print(1)
    exit(0)

# 親の数*子の数を求める
parent = c[0]
ans = c[0]
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)

# 根は0である必要がある。
if not(0 in c):
    print(0)
    exit(0)

# N = 1の時は1
if N == 1:
    print(1)
    exit(0)

# 親の数*子の数を求める
parent = c[0]
ans = 1
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)

# 根は0である必要がある。
# 0が1つでない場合の答えは0になる
if not(0 in c):
    print(0)
    exit(0)
elif c[0] != 1:
    print(0)
    exit(0)

# N = 1の時は1
if N == 1:
    print(1)
    exit(0)

# 親の数*子の数を求める
parent = 1
ans = 1
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)

# 根は0である必要がある。
# 0が1つでない場合の答えは0になる
if not(0 in c):
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()

# 0からDの最大値までの各値が1個以上あること
# for i in range(max(D)+1):
#     if not(i in c):
#         print(0)
#         exit()

# N = 1の時は1
if N == 1:
    print(0)

# 親の数*子の数を求める
parent = 1
ans = 1
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(D)

# 根は0である必要がある。
# 0が1つでない場合の答えは0になる
if not(0 in c):
    print(0)
    exit()
elif c[0] != 1:
    print(0)
    exit()

# 0からDの最大値までの各値が1個以上あること
for i in range(max(D)+1):
    if not(i in c):
        print(0)
        exit()

# N = 1の時は1
if N == 1:
    print(0)

# 親の数*子の数を求める
parent = 1
ans = 1
for i in range(1, max(D)+1):
    ans = (parent**c[i])*ans
    parent = c[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))
Dc = collections.Counter(D)
count=1
if D[0] !=0 or Dc[0]>1:
    print(0)
else:
    for i in range(1,max(Dc.keys())+1):
        count *=pow(Dc[i-1],Dc[i])
    print(count)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
D=list(map(int,input().split()))
Dc = collections.Counter(D)
count=1
if D[0] !=0 or( D[0]==0 and Dc[0]>1):
    print(0)
else:
    for i in range(1,max(Dc.keys())+1):
        count *=pow(Dc[i-1],Dc[i])
    print(count)

Submission status: Wrong Answer

Solution code:
# import math
# import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
# dcnt = collections.Counter(d)
cnt = [0]*10**5
mv = max(d)
for i in d:
    cnt[i] += 1
# print(cnt[:mv+1]
if d[0] != 0:
    print(0)
    exit()
ans = 1
for i, v in enumerate(cnt[:mv+1]):
    if v == 0:
        print(0)
        exit()
    else:
        c = cnt[i-1]**v % mod
        ans *= c
        ans %= mod
            # print(ans, c)

print(ans)

Submission status: Wrong Answer

Solution code:
# import math
# import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
# dcnt = collections.Counter(d)
cnt = [0]*10**5
mv = max(d)
for i in d:
    cnt[i] += 1
# print(cnt[:mv+1])
ans = 1
for i, v in enumerate(cnt[:mv+1]):
    # print(i, v)
    if i == 0:
        if v == 1:
            continue
        else:
            print(0)
            exit()
    else:
        if v == 0:
            print(0)
            exit()
        else:
            c = cnt[i-1]**v % mod
            ans *= c
            ans %= mod
            # print(ans, c)

print(ans)

Submission status: Wrong Answer

Solution code:
# import math
# import collections
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
# dcnt = collections.Counter(d)
cnt = [0]*10**5
mv = max(d)
for i in d:
    cnt[i] += 1
# print(cnt[:mv+1])
ans = 1
for i, v in enumerate(cnt[:mv+1]):
    # print(i, v)
    if i == 0:
        if v == 1:
            continue
        else:
            print(0)
            exit()
    else:
        if v == 0:
            print(0)
            exit()
        else:
            c = cnt[i-1]**v
            ans *= c
            ans %= mod
            # print(ans, c)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
count = [0]*n
ans = 1
for d in map(int,input().split()):
    count[d] += 1
for i in range(1,n):
    if count[0]!=1:
        ans = 0
        break
    if count[i]==0:
        if any(k!=0 for k in count[i:]):
            ans = 0
        break
    ans *= (count[i-1]**count[i])%998244353
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

n=int(input())
d=lnii()

mod=998244353

c=Counter(d)
max_key=max(d)

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

ans=1
patterns=1
for i in range(max_key+1):
  p_num=c[i]
  ans=ans*(patterns**p_num)
  ans%=mod
  patterns=p_num

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
count = [0]*n
ans = 1
for d in map(int,input().split()):
    count[d] += 1
for i in range(1,n):
    if count[i]==0:
        if any(k!=0 for k in count[i:]):
            ans = 0
        break
    ans *= (count[i-1]**count[i])%998244353
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
dic = defaultdict(int)
MOD = 998244353
N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
store = [0 for _ in range(MAX+1)]

for x in A:
  store[x] += 1

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

ans = 1
for i in range(MAX):
  ans = ans*pow(store[i],store[i+1],MOD)
print(ans%MOD)

Submission status: Wrong Answer

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

for x in A:
  dic[x] += 1

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

K = list(dic.keys())
MAX = max(K)
ans = 1
for i in range(MAX):
  ans = ans*pow(dic[i],dic[i+1],MOD)
print(ans%MOD)

Submission status: Wrong Answer

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

for x in A:
  dic[x] += 1

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

K = list(dic.keys())
MAX = max(K)
ans = 1
for i in range(1,MAX):
  ans = ans*pow(dic[i],dic[i+1],MOD)
print(ans%MOD)

Submission status: Wrong Answer

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

for x in A:
  dic[x] += 1

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

K = list(dic.keys())
MAX = max(K)
ans = 1
for i in range(1,MAX):
  ans = ans*pow(dic[i],dic[i+1],MOD)
print(ans)

Submission status: Wrong Answer

Solution code:
p=998244353
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
N = int(input())
D = list(map(int,input().split()))
D.insert(0,0)
C = {i:0 for i in range(N)}
for i in range(1,N+1):
    C[D[i]] += 1
if C[0]!=1 or D[1]!=0:
    cnt = 0
else:
    C = sorted(list(C.items()),key=lambda x:x[0])
    ind = 0
    for i in range(N):
        if C[i]==0:
            ind = i
            break
    flag = 0
    if ind>0:
        for i in range(ind+1,N):
            if C[i]>0:
                flag = 1
                break
    if flag==1:
        cnt = 0
    else:
        cnt = 1
        for i in range(1,N):
            if C[i][1]==0:break
            c0 = C[i-1][1]
            c1 = C[i][1]
            cnt = (cnt*(pow(c0,c1)))%p
print(cnt)