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 statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
flag = False
n = I()
D = readInts()
dic = defaultdict(int)
for i in range(n):
    dic[D[i]] += 1
# 後ろから見る
for i in range(n-1,0,-1):
    if dic[i] != 0:
        flag = True
    if flag and dic[i] == 0:
        print(0)
        exit()
if dic[0] != 1: # 距離が0(頂点が1)が絶対に存在しないと駄目
    print(0)
    exit()
if D[0] != 0: # 頂点1が絶対に存在 距離が 0
    print(0)
    exit()
ans = 1
#print(dic)
for i in range(1,n):
    ans *= pow(dic[i-1],dic[i],mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
flag = False
n = I()
D = readInts()
dic = defaultdict(int)
for i in range(n):
    dic[D[i]] += 1
# 後ろから見る
for i in range(n-1,0,-1):
    if dic[i] != 0:
        flag = True
    if flag and dic[i] == 0:
        print(0)
        exit()
if dic[0] != 1: # 距離が0(頂点が1)が絶対に存在しないと駄目
    print(0)
    exit()
if D[0] != 0: # 頂点1が絶対に存在 距離が 0
    print(0)
    exit()
ans = 1
print(dic)
for i in range(1,n):
    ans *= pow(dic[i-1],dic[i],mod)
    ans %= mod
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
mod=998244353
b=[0]*n
for i in a:
    b[i]+=1
ans=0
if a[0]<1 and 1==b[0]:
    ans=1
for i,j in zip(b,b[::1]):
    ans*=i**j
    ans%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
mod=998244353
d={}
for i in a:
  d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]+1:
    ans=0
for i in range(1,len(b)):
    ans*=b[i-1][1]**b[i][1]
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
mod=998244353
d={}
for i in a:
  d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]:
    ans=0
for i in range(1,len(b)):
    ans*=b[i-1][1]**b[i][1]
    ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a[0]:
    print(0)
    exit()
a.sort()
j=0
l=list()
#print(a)
for i in range(max(a)+1):
    k=0
    while j<n and a[j]==i:
        j+=1
        k+=1
        #print(l,j,k)
    l.append(k)
#print(l)
p=l[0]==1
for i in range(len(l)-1):
    #print(p)
    p*=pow(l[i],l[i+1],998244353)
print(p)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
d = list(map(int, input().split()))
if d[0] != 0 or 0 in d[1:]:
    print(0)
else:
    c = Counter(d)
    ans = 1
    for i in range(1, len(c)):
        ans *= c[i-1] ** c[i]
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import*
n, f, *d= map(int, open(0).read().split())
c = Counter(d)
if f or c[0] > 1:
    exit(print(0))
MOD = 998244353
m = 1
for i in range(1, max(d)):
    m *= pow(c[i], c[i+1], MOD)
    m %= MOD
print(m)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import*
n, f, *d= map(int, open(0).read().split())
if f:
    exit(print(0))
MOD = 998244353
m = 1
c = list(Counter(sorted(d)).values())
for i in range(len(c) - 1):
    m *= pow(c[i], c[i+1], MOD)
    m %= MOD
print(m)

Submission status: Wrong Answer

Solution code:
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = int(input())
data = list(map(int, input().split()))
data = count(data)
mod = 998244353
if 0 not in data or data[0] != 1:
    print(0)
    exit()
ans = 1
for depth, edges in data.items():
    if depth == 0:
        continue
    if depth - 1 not in data:
        print(0)
        exit()
    ans *= data[depth-1]**edges
    ans %= mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
def count(l):
    res = {}
    for d in l:
        if d in res:
            res[d] += 1
        else:
            res[d] = 1
    return res

n = int(input())
data = list(map(int, input().split()))
data = count(data)
if 0 not in data or data[0] != 1:
    print(0)
    exit()
ans = 1
for depth, edges in data.items():
    if depth == 0:
        continue
    if depth - 1 not in data:
        print(0)
        exit()
    ans *= data[depth-1]**edges
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    L = max(values)
    M = set(list(range(L+1)))
    #print(M,L)
    if M == set(values) and 0 not in D[1:]:
        ans = 1
    else:
        ans = 0
    for i in range(1,len(values)):
        ans *= pow(i, Dep[i], mod)
        #print(i,Dep[i])
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    if 0 in D[1:]:
        ans = 0
    else:
        ans = 1
    for i in range(1,len(values)):
        ans *= pow(i, Dep[i], mod)
        #print(i,Dep[i])
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    ans = 1
    for i in range(1,len(values)):
        if Dep[i] == 0:
            ans = 0
        ans *= pow(i, Dep[i], mod)
        #print(i,Dep[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    ans = 1
    for i in range(1,len(values)):
        if Dep[i] == 0:
            ans = 0
        ans *= pow(i, Dep[i], mod)
        #print(i,Dep[i])
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    ans = 1
    for i in range(1,len(values)):
        ans *= pow(i, Dep[i], mod)
        #print(i,Dep[i])
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    for i in range(len(values)):
        if i not in values:
            ans = 0
        else:
            ans = 1
    for i in range(1,len(values)):
        ans *= pow(i, Dep[i], mod)
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections
mod = 998244353

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

if D[0] != 0:
    print(0)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    if len(values)-1 != max(values):
        ans = 0
    else:
        ans = 1
    for i in range(1,len(values)):
        ans *= pow(i, Dep[i], mod)
        ans %= mod
    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)
else:
    Dep = collections.Counter(D)
    values, counts = zip(*Dep.most_common())
    #print(values)
    #print(counts)
    #print(Dep)
    
    for i in range(len(values)):
        if i not in values:
            ans = 0
        else:
            ans = 1
    for i in range(1,len(values)):
        ans *= i ** (Dep[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()
max_num = 10**5+1
num_list = [0] * (max_num)

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

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

ans = 1
for i in range(2, max_num):
    if num_list[i] != 0:
        ans *= pow(num_list[i-1], num_list[i], 998244353)

else:
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()
A = li()
max_num = 10**5+1
num_list = [0] * (max_num)

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

ans = 1
flag = 0
for i in range(2, max_num):
    if num_list[i] != 0:
        ans *= pow(num_list[i-1], num_list[i], 998244353)
        flag = 1

if not flag:
    print(0)
else:
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int, input().split()))
DL = [0] * N
mod = 998244353
if D[0] != 0:
    print(0)
    exit()

for d in D:
    DL[d] += 1

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

ans = 1
for i in range(1, N):
    if DL[i] == 0:
        if sum(DL[i:]) != 0:
            print(0)
            exit()
        else:
            print(ans%mod)
            exit()

    ans *= pow(DL[i-1], DL[i], mod)
    ans %= mod

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
DL = [0] * N
mod = 998244353

for d in D:
    DL[d] += 1

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

ans = 1
for i in range(1, N):
    if DL[i] == 0:
        if sum(DL[i:]) != 0:
            print(0)
            exit()
        else:
            print(ans)
            exit()

    ans *= pow(DL[i-1], DL[i], mod)
    ans %= mod

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

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

c.sort()
    
prev_k = 0
prev_v = 1
ans = 1
mod = 998244353
for k, v in c[1:]:
    if k - prev_k > 1:
        print(0)
        sys.exit()
    else:
        ans *= pow(prev_v, v) % mod
        ans %= mod
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
mod = 998244353
for k, v in c[1:]:
    if k - prev_k > 1:
        print(0)
        sys.exit()
    else:
        ans *= pow(prev_v, v) % mod
        ans %= mod
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
mod = 998244353
for k, v in c[1:]:
    if k - prev_k > 1:
        print(0)
        sys.exit()
    else:
        ans *= prev_v**v % mod
        ans %= mod
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if c[0] != 1:
        return 0
    max_c = max(c)
    for i in range(max_c + 1):
        if i not in c:
            return 0

    c = list(c.items())
    c.sort()

    prev = 1
    ans = 1
    mod = 998244353

    for _, i in c[1:]:
        if prev * 2 < i:
            return 0
        else:
            ans *= pow(prev, i) % mod
            ans %= mod
            prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.items())
    c.sort()

    prev = 1
    ans = 1
    mod = 998244353

    for _, i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    arr.sort()

    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    arr.sort()

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        ans *= pow(prev, i) % mod
        ans %= mod
        prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    if arr[0] != 0:
        return 0

    arr.sort()

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        if i > prev * 2:
            return 0
        else:
            ans *= pow(prev, i, mod) % mod
            ans %= mod
            prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    arr.sort()

    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        if i > prev * 2:
            return 0
        else:
            ans *= pow(prev, i, mod) % mod
            prev = i

    return ans % mod


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    arr.sort()

    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        if i > prev * 2:
            return 0
        else:
            ans = ans * pow(prev, i, mod) % mod
            prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
from collections import Counter


def solve(n, arr):
    arr.sort()

    if arr[0] != 0:
        return 0

    c = Counter(arr)

    if len(c) != max(c.keys()) + 1:
        return 0

    c = list(c.values())

    prev = c[0]
    ans = 1
    mod = 998244353

    for i in c[1:]:
        if i > prev * 2:
            return 0
        else:
            ans = ans * prev**i % mod
            prev = i

    return ans


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

print(solve(n, arr))

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
for k, v in c[1:]:
    if k - prev_k > 1 or prev_v * 2 < v:
        print(0)
        sys.exit()
    else:
        ans *= prev_v**v
        prev_k = k
        prev_v = v

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
for k, v in c[1:]:
    if k - prev_k > 1 or prev_v * 2 < v:
        print(0)
        sys.exit()
    else:
        ans *= prev_v**v % 998244353
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
for k, v in c[1:]:
    if k - prev_k > 1 or prev_v * 2 < v:
        print(0)
        sys.exit()
    else:
        ans *= prev_v**v
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

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

c = list(Counter(arr).items())

c.sort()

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

prev_k = 0
prev_v = 1
ans = 1
for k, v in c[1:]:
    if k - prev_k > 1 or prev_v * 2 < v:
        print(0)
        sys.exit()
    else:
        ans *= prev_v**v
        prev_k = k
        prev_v = v

print(ans)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

N = getN()
D = getList()
if D[0] != 0:
    print(0)
    exit()
D = Counter(D)
D = sorted(D.items(), key = lambda x: x[0])
if D[0][1] != 1:
    print(0)
    exit()

x1 = 0
y1 = 1
ans = 1
for i in D[1:]:
    if x1 + 1 != i[0]:
        ans = 0
        break
    ans *= y1 ** i[1]
    x1 = i[0]
    y1 = i[1]
print(ans)

Submission status: Wrong Answer

Solution code:
n,*d=map(int,open(0).read().split())
mod=998244353
c=[0]*(max(d)+1)
for i in d:
  c[i]+=1
ans=1
for i in range(max(d)):
  ans*=pow(c[i],c[i+1],mod)
  ans%=mod
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d_list = list(map(int,input().split()))
p = 998244353
import collections
result = 0
if d_list[0] != 0:
  print(result)
else:
  result = 0
  c = collections.Counter(d_list)
  for i in range(1,max(d_list) + 1):
    if i == 1:
      result += 1
    elif  c[i] == 0:
        result = 0
    else:
      result = result * (c[i -1] ** c[i])

  print(result % p)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

d_count = Counter(d)

ans = 1
pre_count = 1
for i,(dist,count) in enumerate(sorted(d_count.items())):
    if i != dist or (i==0 and count != 1):
        ans = 0
        break
    
    ans *= pow(pre_count,count,MOD)
    ans %= MOD
    
    pre_count = count
    
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

MOD = 998244353

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

d_count = Counter(d)

ans = 1
pre_count = 1
for i,(dist,count) in enumerate(sorted(d_count.items())):
    if i != dist or (i==0 and count >1):
        ans = 0
        break
    
    ans *= pow(pre_count,count,MOD)
    ans %= MOD
    
    pre_count = count
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

MOD = 998244353

dn = Counter(d)
ans = 1
if dn[0] != 1 or d[0] != 0: ans = 0
else:
    for i in range(1, max(d)+1):
        ans *= (dn[i-1]**dn[i])%MOD
    
print(ans)

Submission status: Wrong Answer

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

MOD = 998244353

dn = Counter(d)
ans = 1

for i in range(1, max(d)+1):
    ans *= (dn[i-1]**dn[i])%MOD
    
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache

@lru_cache(maxsize=None)

def kaijou(n):
    if n <= 1:
        return 1
    return kaijou(n-1)*n

def H(n,r):
    return kaijou(n+r-1)/kaijou(r)/kaijou(n-1)

from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or D.count(0) != 1:
    print(0)
    sys.exit()
D = Counter(D)
L = sorted(D.items())
pk = 0
pv = 1
ans = 1
for i,j in L:
    if i == 0:
        continue
    if i != pk+1:
        print(0)
        break
    ans *= pv**j
    ans %= 998244353
    pk = i
    pv = j
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
dist_map = [0]*n
for dist in d:
    dist_map[dist] += 1
ans = 1
for i in range(1, n):
    ans *= pow(dist_map[i-1], dist_map[i], MOD)
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
dist_map = [0]*(n+1)
for dist in d:
    dist_map[dist] += 1
ans = 1
for i in range(1, n+1):
    ans *= pow(dist_map[i-1], dist_map[i]) % MOD
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
dist_map = [0]*n
for dist in d:
    dist_map[dist] += 1
ans = 1
for i in range(1, n):
    ans *= pow(dist_map[i-1], dist_map[i]) % MOD
    ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 998244353
n = int(input())
d = list(map(int, input().split()))
dist_map = [0]*n
for dist in d:
    dist_map[dist] += 1
ans = 1
for i in range(1, n):
    if dist_map[i] > 0:
        ans *= pow(dist_map[i-1], dist_map[i]) % MOD
        ans %= MOD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections

input = sys.stdin.readline
MOD = 998244353

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

    if D[0] != 0:
        print(0)
        return
    
    D.sort()
    Dmax = max(D)
    Ditems = collections.Counter(D).items()
    Dcount = list(zip(*Ditems))

    Dset = set(Dcount[0])
    if Dset != set(range(Dmax+1)):
        print(0)
        return
    
    ans = 1
    for i in range(2, Dmax+1):
        ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD)
        ans %= MOD

    print(ans%MOD)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import collections

input = sys.stdin.readline
MOD = 998244353

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

    if D[0] != 0:
        print(0)
        return
    
    D.sort()
    Dmax = max(D)
    Ditems = collections.Counter(D).items()
    Dcount = list(zip(*Ditems))

    Dset = set(Dcount[0])
    if Dset != set(range(Dmax+1)):
        print(0)
        return
    
    ans = 1
    for i in range(2, Dmax+1):
        ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD)

    print(ans%MOD)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
MOD = 998244353

n = int(input())
d = [int(_) for _ in input().split()]

ans = 1
if d[0] != 0:
    ans = 0
else:
    D = sorted(collections.Counter(d).most_common())
    cnt = 0
    prev = 1
    for i in D:
        if i[0] == cnt:
            ans = ans * pow(prev, i[1], MOD) % MOD
            prev = i[1]
        else:
            ans = 0
            break
        cnt += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
# from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

MOD = 998244353

def solve():
    n = int(input())
    d = [int(x) for x in input().split()]
    f = [0] * n
    for e in d:
        f[e] += 1
    
    ok = f[0] != 0
    z = 0
    ans = 1
    for i in range(1, n):
        if (f[i] == 0): z = 1
        if (z and f[i]): ok = 0
        ans *= pow(f[i-1], f[i], MOD)
        ans %= MOD
    print(ans * ok)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
# from collections import defaultdict, deque
# from math import sqrt, gcd, factorial, tan, pi, sin, cos
def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline()[:-1]

MOD = 998244353

def solve():
    n = int(input())
    d = [int(x) for x in input().split()]
    f = [0] * n
    for e in d:
        f[e] += 1
    
    ok = f[0] == 1
    z = 0
    ans = 1
    for i in range(1, n):
        if (f[i] == 0): z = 1
        if (z and f[i]): ok = 0
        ans *= pow(f[i-1], f[i], MOD)
        ans %= MOD
    print(ans * ok)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()



"""
1 -> (1, 2) -> (2 ** 3, 3) -> (3, 1)

"""

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
MOD = 998244353
N = int(input())
D = list(map(int,input().split()))
d = defaultdict(int)
for i in D:
    d[i] += 1
ans = 1
if d[0] != 1:
    print(0)
else:
    for i in range(1,N):
        ans = ans*pow(d[i-1],d[i],MOD)
    print(ans%MOD)