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 defaultdict, deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys
import random
import itertools
import math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt


def LI(): return list(map(int, input().split()))


def LF(): return list(map(float, input().split()))


def LI_(): return list(map(lambda x: int(x)-1, input().split()))


def II(): return int(input())


def IF(): return float(input())


def LS(): return list(map(list, input().split()))


def S(): return list(input().rstrip())


def IR(n): return [II() for _ in range(n)]


def LIR(n): return [LI() for _ in range(n)]


def FR(n): return [IF() for _ in range(n)]


def LFR(n): return [LI() for _ in range(n)]


def LIR_(n): return [LI_() for _ in range(n)]


def SR(n): return [S() for _ in range(n)]


def LSR(n): return [LS() for _ in range(n)]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]


def sosu(x):
    for i in range(2, int(sqrt(x)+1)):
        if x % i == 0:
            return False
    return True


mod = 1000000007
inf = float('INF')


def A():
    N = II()

    if N % 2 == 0:
        print((N//2)-1)
    else:
        print(N//2)
    return

# B


def B():
    N = II()
    D = LI()
    if D[0] != 0:
        print(0)
        return

    if D.count(0) != 1:
        print(0)
        return
    ans = 1
    count = D.count(1)
    for i in range(1, N-1):
        x = D.count(i)
        y = D.count(i+1)
        if x == 0:
            print(0)
            return
        ans = ans*(x ** y)
        count += y
        if count == len(D):
            break
    print(ans)

    return

# C


def C():
    N = II()
    A = LI()
    B = LI()

    L = []
    count = 0
    for i in range(2, int(sqrt(N)+2)):
        if N % i == 0:
            L.append(N/i)
            count = 1
    if count == 0:
        print(N-1)
    else:
        print(int(L[-1]-2+(N/L[-1])))

    return

# D


def D():

    a, b, x = LI()
    BIG = a*a*b/2
    if x > BIG:
        y = 2*b-(2*x/a/a)
        print(math.degrees(math.atan(y/a)))
    else:
        y = 2*x/a/b
        print(math.degrees(math.atan(b/y)))
    return

# E


def E():
    N, K = LI()
    A = LI()
    F = LI()
    A.sort(reverse=True)
    F.sort()
    cost = []
    for i in range(len(N)):
        cost.append(A[i]*F[i])

    a = F[cost.index(max(cost))]

    return

# F


def F():
    N, M = LI()

    value = [0] * M
    power = [0] * M
    for i in range(M):
        a, b = LI()
        value[i] = a
        c = LI()
        L = ['0'] * N
        for k in c:
            L[k - 1] = '1'
        bint = ''.join(L)
        power[i] = int(bint, 2)
    bint = ''.join(list(['1'] * N))
    dp = [inf] * (int(bint, 2)+1)
    t = 0
    cost = 0

    dp[0] = 0
    for s in range(int(bint, 2) + 1):
        for i in range(M):
            t = s | power[i]
            cost = dp[s] + value[i]
            dp[t] = min(dp[t], cost)
    print(-1) if(dp[-1] == inf) else print(dp[-1])

    return

    # you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")


def solution(S):
    # write your code in Python 3.6
    N = len(S)

    pass


# Solve
if __name__ == '__main__':
    B()

Submission status: Wrong Answer

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

c = Counter(D)
max_D = max(D)
if c[0]!=1:
  print(0)
  
elif max_D<=1:
  print(1)
  
else:
  answer=1
  for i in range(2,max_D+1):
    c_i2 = c[i]
    c_i1=c[i-1]
    answer *= c_i1**c_i2
    
  print(answer)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
d = list(map(int, input().split()))
b = ans = 1
maxd = max(d)
if d[0] == 0 and d.count(0) == 1:
    for i in range(1, maxd+1):
        dc = d.count(i)
        if dc == 0:
            print(0)
            exit()
        ans *= np.power(b, dc)
        b = dc
    print(ans % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
def mod_pow(a, n, mod):
    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def main(n, d):
    MOD = 998244353
    depth = max(d)
    counts = [d.count(i) for i in range(depth + 1)]
    if counts[0] != 1:
        return 0
    if counts.count(0):
        return 0
    pows = [mod_pow(a=counts[i - 1], n=counts[i], mod=MOD) for i in
            range(1, depth + 1)]
    patterns = 1
    for p in pows:
        patterns *= p
        patterns %= MOD
    return patterns


if __name__ == '__main__':
    N = int(input())
    D = list(map(int, input().split()))
    print(main(n=N, d=D))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from sys import stdin
input = stdin.readline

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

c=Counter(d)
d_max=max(d)
ans=1
flag=True

if d[0]!=0:
    print(0)
elif d.count(0)>1:
    print(0)
elif d_max==1:
    print(d.count(1))
else:
    for i in range(2, d_max+1):
        if c[i-1]==0:
            flag=False
            break
        else:
            ans*=(c[i-1]**c[i])%998244353

    print(ans%998244353 if flag else 0)

Submission status: Wrong Answer

Solution code:
N = int(input())
D_list = [int(s) for s in input().split(" ")]

path = [D_list.count(i) for i in range(0,max(D_list) + 1)]

res = 1
for j in range(0,len(path)-1):
    res *= path[j] ** path[j+1]

print(res % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(x) for x in input().split()]
s.sort()
count = []
deep,c,ans = 0,1,1
for i in range(n):
  if i == n-1:
    count.append(c)
  elif s[i] == s[i+1]:
    c+=1
  elif s[i] == s[i+1]-1:
    count.append(c)
    c = 1
  else:
    ans = 0
    
for j in range(len(count)-1):
  if j == len(count) - 1:
    ans 
  ans *= count[j]**count[j+1]
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
c=0
a = list(map(int,input().split()))
a.sort()
mem = {}
mem['-1']=1
count = 1
if n ==1:
    if a[0] ==0:
        print(1)
    else:
        print(0)
else:
    for v in a:
        need = v-1
        if str(need) in mem:
            count *= mem.get(str(need))
            count %=mod
        else:
            count = 0
            break
        if str(v) in mem:
            mem[str(v)] = mem.get(str(v))+1
        else:
            mem[str(v)] = 1
    if '0' in mem and mem.get('0')>1:
        print(0)
    else:
        print(count%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = Counter(list(map(int, input().split())))
if Dlist[0] == 1:
    num = 1
    mae = 1
    for key, value in sorted(Dlist.items()):
        num *= (mae ** value) % 998244353
        mae = value
    print(num % 998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

N = int(input())
D = [int(x) for x in input().split()]
D_counter = Counter(D)
ans = 1

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

for d in D_counter:
    if d - 1 in D_counter:
        ans *= (D_counter[d - 1] ** D_counter[d]) % 998244353
        ans = ans % 998244353
    else:
        if not d == 0:
            print(0)
            sys.exit()
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)


@mt
def slv(N, D):
    if D[0] != 0:
        return 0
    C = Counter(D)
    ans = 1
    M = Mod(998244353)
    for i in range(max(D)):
        if C[i] == 0:
            return 0
        ans = M.mul(ans, M.pow(C[i], C[i+1]))
    return ans


def main():
    N = read_int()
    D = read_int_n()
    print(slv(N, D))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = [int(i) for i in input().split()]
b = collections.Counter(a)
branch = b[1]
ct = 1
for i in range(max(a)+1):
    if i == 0 or i == 1:
        continue
    else:
        ct *= branch**b[i]
        branch = b[i]
if b[0] != 0:
    print(0)
else:
    print(ct)

Submission status: Wrong Answer

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

counter = list(map( (lambda x: 0), range(N) ))

for distance in Ds:
    counter[ distance ] += 1   

if N == 1:
    if counter[0] == 1:
        result = 1
    else:
        result = 0
else:
    if counter[0] != 1 :
        result = 0
    else:
        result = 1

if N > 2:
    for distance in range(2,N):
        temp = pow( counter[distance-1], counter[distance] )
        result = (result * temp) % 998244353
         
print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

if n == 1:
    if d[0] == 0:
        print(1)
        exit()
    else:
        print(0)
        exit()

if d[0] == 0 and d[1] != 0:
    pass
else:
    print(0)
    exit()

set_d = set(d)
list_d = list(set_d)
list_d.sort()
dict_d = Counter(d)

ans = 1
cnt = 1
temp = 0
check = 1

for i in list_d:
    if i == 0:
        continue
    if i != temp + 1:
        print(0)
        exit()
        
    temp = i
    cnt = dict_d[i]
    ans = ans * check**cnt
    check = cnt
    
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
Dlist = Counter(list(map(int, input().split())))
if Dlist[0] == 1:
    num = 1
    mae = 1
    for key, value in sorted(Dlist.items()):
        num *= (mae ** value)
        mae = value
    print(num % 998244353)
else:
    print(0)

Submission status: Wrong Answer

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

if D[0] != 0:
    print(0)
else:
    mod = 998244353
    D.sort()
    ans = 1
    distance = 0
    prev = 1
    now = 0
    for i in range(len(D)):
        if D[i] == distance:
            now += 1
        elif D[i] == distance + 1:
            ans = ans * prev ** now % mod
            prev = now+0
            now = 1
            distance += 1
        else:
            ans = 0
            break
    else:
        ans = ans * prev ** now % mod
    
    print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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

const = 998244353

c = collections.Counter(d)

m = max(d)

a = c[0]

if a == 0:
    print(0)
else:
    ans = a

    new = ans

    for i in range(m):
        j = i + 1
        old = new
        new = c[j]
        if new == 0:
            ans = 0
            break
        else:
            ans = ans * (pow(old, new) % const) % const

    print(ans)

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans >= 1:
    for i in range(1,maxkey): 
        ans=ans*dic[i]**dic[i+1]%MOD
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = list(map(int, input().split()))
item = 0
sum = 0
node = 0
count = 0
before = 0

for i in range(N):
    count = s.count(i)
    node += count
    if i == 0:
        if count != 1:
            break
        else:
            before = 1
            sum = 1
    else:
        if count == 0:
            break
        else:
            sum = sum * (before ** count)
            before = count

if node != len(s):
    print("0")
else:
    print(sum%998244353)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
longest = max(D)
c = collections.Counter(D)
ans = 1
for i in range(longest):
    ans = ans * (c[i])**(c[i+1]) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
mod = 998244353

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

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

if p[0]!=1:
    print(0)
    exit()
ans = 1
j = 1
for i in range(1,n):
    if p[i]==0:
        break

    ans = (ans*(p[i-1]**p[i]))%mod
    j +=p[i]
if j==n:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

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

print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

d.sort()
ans = 1

c = collections.Counter(d)
x = list(c.items())
if x[0][0] == 0 and x[0][1] == 0:
    print(0)
    exit()
elif x[0][0] == 1:
    print(0)
    exit()

x.pop(0)


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(len(x)-1):
    pre_num = x[i][1]
    forward_num = x[i+1][1]
    if pre_num == 1:
        ans *= forward_num
    elif forward_num == 1:
        ans *= pre_num
    elif pre_num < forward_num:
        ans *= math.factorial(pre_num) * cmb(forward_num+1, pre_num-1)
    else:
        ans *= (pre_num + cmb(pre_num, forward_num) * math.factorial(forward_num))
    ans = ans % num

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

N=int(input())
D=list(map(int,input().split()))
if D[0]==0 and len(set(D))==max(D)+1:
  A=collections.Counter(D)
  c=1
  for i in range(max(D)):
    c*=A[i]**A[i+1]
  ans=c%998244353  
  print(ans)
else:
  print(0)

Submission status: Wrong Answer

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

if min(Ds)!=0 or Ds.count(0)!=1:
    print(0)
else:
    Ans=[0]*(max(Ds)+1)
    Ans[0]=1
    Count=[0]*(max(Ds)+1)
    Count[0]=1
    for i in range(1, max(Ds)+1):
        Count[i]=Ds.count(i)
        Ans[i]=(Ans[i-1]*(Count[i-1]**Count[i]))%998244353

    print(Ans[max(Ds)])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

#E = sorted(D)

myans = 0

for i in D:
    if i == 0:
        myans = 1
    else:
        myans *= i
        
print(myans%998244353)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def solve(N,D):
    if D[0]:
        return 0

    #try:
    #    idx = D[1::].index(0)
    #    for d in D[idx::]:
    #        if d:
    #            return 0
    #except:
    #    pass
    
    nums = Counter(D)
    nums = sorted(nums.items())
    if len(nums) != nums[-1][0]+1:
        return 0
        
    #print(nums)
    ans = 1
    for i in range(len(nums)-1):
        ans *= nums[i][1]**nums[i+1][1]
        ans %= 998244353
    return ans

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
D = list(map(int,input().split()))
if not D[0] == 0:
    print("0")
if min(D[1:]) == 0:
    print("0")
else:
    ans = [pow(i,D.count(i)) for i in range(1,max(D)+1)]
    ans = np.prod(ans, axis = 0)
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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

    count = {}
    pre = 0
    for i, d_i in enumerate(sorted(d)):
        if d_i != pre and d_i != pre + 1:
            print(0)
            return

        if d_i not in count:
            count[d_i] = 0
        count[d_i] += 1
        pre = d_i

    ans = 1
    pre = 1
    for i, c in count.items():
        if i == 0:
            continue

        ans *= (nCr(pre, 1) ** c)
        ans = ans % 998244353
        pre = c

    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    d = list(map(int, sys.stdin.readline().strip().split(" ")))
    solve(n, d)

Submission status: Wrong Answer

Solution code:
import heapq

n = int(input())
d = list(map(int, input().split()))
d.sort()
if d[0] != 0:
    print(0)
else:
    pre = -1
    num = 0
    ans = 1
    for i in range(len(d)):
        if d[i] == 0:
            if i > 0:
                print(0)
                break
            else:
                continue
        if d[i] == pre:
            num += 1
            if i == len(d)-1:
                ans *= d[i]**num
        elif d[i] - d[i-1] > 1:
            print(0)
            break
        else:
            if i == 1:
                num = 1
                pre = d[i]
                continue
            ans *= d[i-1]**num
            pre = d[i]
            if i == len(d)-1:
                ans *= pre
            num = 1
    else:
        print(ans)

Submission status: Wrong Answer

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

ans = 1
if d[0] != 0 or sum(d) < n - 2 or sum(d) > (n * (n - 1) // 2) + 1:
    print(0)
else:
    l = [0] * (max(d) + 1)
    for i in range(n):
        l[d[i]] += 1

    if l[0] != 1:
        print(0)
    else:
        for j in range(1, len(l)):
            if l[j] == 0:
                ans = 0
                print("a")
                break
            else:
                x = l[j - 1] ** l[j] % mod
                ans *= x
                ans %= mod
        print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
ans = 1
if D[0] != 0 or D.count(0) > 1:
  print(0)
  exit()

prev = 1
for i in range (N):
  count = D.count(i+1)
  ans = ans * ((prev**count) %998244353 ) 
  prev = count
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]

initial = d[0]
maximum = max(d)

count_dict = {}
count_dict[initial] = 1

for i in range(1, n):
    if d[i] <= initial:
        print(0)
        exit()

    if d[i] in count_dict.keys():
        count_dict[d[i]] += 1
    else:
        count_dict[d[i]] = 1

count_dict = sorted(count_dict.items())

# print(len(count_dict))

ans = 1
for i in range(len(count_dict)-1):
    if count_dict[i][0] + 1 != count_dict[i+1][0]:
        print(0)
        exit()

    ans *= count_dict[i][1] **count_dict[i+1][1]

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

pattern_dic = {}
zero_flag = 0
ans = 1
if D_list[0] != 0:
    print(0)
else:
    for i in range(1, N):
        pattern_dic[D_list[i]] = pattern_dic.get(D_list[i], 0) + 1
    if 1 in pattern_dic:
        before_num = pattern_dic[1]
        for j in range(2, max(pattern_dic.keys()) + 1):
            if j in pattern_dic:
                ans *= before_num ** pattern_dic[j]
                before_num = pattern_dic[j]
            else:
                zero_flag = 1
                break
    else:
        zero_flag = 1

    if zero_flag == 1:
        print(0)
    else:
        print(ans)

Submission status: Wrong Answer

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

for i in range(max(d)+1):
    count=d.count(i)
    num.append(count)
ans=1
if d[0]!=0:
    print(0)
else:
    for i in range(1, max(d)+1):
        ans*=num[i-1]**num[i]
    print(ans)

Submission status: Wrong Answer

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    Ds = [int(d) for d in input().split()]

    l = 0
    r = 1

    if 0 not in Ds:
        print(0)
        return
    Ds.remove(l)
    if 0 in Ds:
        print(0)
        return
    c = []
    while len(Ds) > 0:
        cnt = 0
        l = l + 1
        while l in Ds:
            Ds.remove(l)
            cnt = cnt + 1
        c.append((r, cnt))
        r = cnt
        
    ans = 1
    divider = 998244353
    for i, j in c:
        r = (i**j)%divider
        ans = ans%divider
        ans = (ans*r)%divider
    
    print(ans)






# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("nikkei2019-2-qual","b",main)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
elif d[-1] > n-1:
  print("0")
else:
  for i in range(1,n-1):
    if d[i] == d[i+1]:
      cnt += 1
    else:
      cnt += 1
      li.append(cnt)
      cnt = 0
    if i == n-2:
      if d[n-2] == d[n-1]:
        cnt += 1
        li.append(cnt)
      else:
        li.append(1)
  for i in range(len(li)-1):
    k=1
    for l in range(li[i+1]):
      k = k*li[i]
      if k > 998244353:
        k = k%998244353
    ans = (ans*(k%998244353)%998244353)
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
D = list(map(int,input().split()))
D_ = collections.Counter(D)
ans = 1
for i in range(len(D_)):
    temp = D_[i]
    if  i > 0:
        ans *= D_[i-1] ** D_[i]
        ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
l=[]
if d[0]!=0:
  print(0)
elif 0 in d[1:]:
  print(0)
else:
  for i in range(1,n-1):
    l.append(d.count(i))
    if d.count(i)==0:
      break
  p=1
  for i in range(len(l)-1):
    p*=l[i]**l[i+1]
  print(p%998244353)

Submission status: Wrong Answer

Solution code:
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#print(cnt)
try:
  if cnt[0]!=0:
    ans = 1
    for i in range(len(dict(cnt))-1):
      val_1 = cnt[i]
      val_2 = cnt[i+1]
      ans *= (val_1**val_2)%MOD

    print(ans%MOD)
except KeyError:
  print(0)

Submission status: Wrong Answer

Solution code:
import math
N = int(input().strip())

count = 1
array = list(map(int, input().strip().split(' ')))
for i in range(N):
    if array[i] != 0:
        count = count * array[i]

if array[0] != 0:
    count = 0
ans = count % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
def solve():
    sys.setrecursionlimit(100000)
    mod = 998244353

    N = int(input())
    D = list(map(int, input().split()))
    cnter = collections.Counter(D)
    cnter = sorted(cnter.items())

    ans = 1
    if cnter[0][0] != 0 or cnter[0][1] != 1 : 
        ans = 0
    elif cnter[1][0] != 1:
        ans = 0
    else:
        for i in range(2, len(cnter)):
            if cnter[i][0] != i:
                ans = 0
                break

            else:
                ans *= cnter[i-1][1] ** cnter[i][1] % mod
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
n = int(input())
mod = 998244353
c=0
a = list(map(int,input().split()))
a.sort()
mem = {}
mem['-1']=1
count = 1
if n ==1:
    print(0)
else:
    for v in a:
        need = v-1
        if str(need) in mem:
            count *= mem.get(str(need))
            count %=mod
        else:
            count = 0
            break
        if str(v) in mem:
            mem[str(v)] = mem.get(str(v))+1
        else:
            mem[str(v)] = 1
    if '0' in mem and mem.get('0')>1:
        print(0)
    else:
        print(count%mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = list(map(int,input().split()))
import collections as col
E = col.Counter(D)
def tree(L):
    t = 1
    if L[0] != 1:
        return 0
    else:
        for i in range(1,len(L)):
            t = t * (L[i-1]**L[i])
            t = t % 998244353
        return t
print(tree(E))

Submission status: Wrong Answer

Solution code:
import sys
import math

n = int(input())
d = list(map(int, input().split()))
d.sort()
min_d = d[0]
max_d = d[-1]
mod = 998244353

if d[0] == d[1] or d[0] != 0:
    print(0)
    sys.exit()
count = [0 for _ in range(max_d+1)]
num = 0
counter = 0
for i in range(n):
    if d[i] == num:
        counter += 1
    else:
        if d[i] == num+1:
            count[num] = counter
            counter = 1
            num += 1
        else:
            print(0)
            sys.exit()
count[-1] = counter
ans = 1
for i in range(max_d):
    n = count[i]-1
    m = count[i+1]
    if n == 0:
        ans *= m%mod
    else:
        ans *= (math.factorial(n+m)//(math.factorial(n)*math.factorial(m)))%mod
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
m=l1[-1]
if l1[0]!=0:
  print(0)
else:
  ld=[0 for i in range(m+1)]
  b=False
  for i in range(n):
    ld[l[i]]+=1
  for i in range(1+m):
    if ld[i]==0:
      b=True
  if ld[0]!=1:
    print(0)
  elif b:
    print(0)
  else:
    ans=1
    for i in range(1,m+1):
      num=ld[i-1]**ld[i]
      ans=(ans*num)%(998244353)
    print(ans%(998244353))

Submission status: Wrong Answer

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

import collections
dic = collections.Counter(D)

maxkey = max(dic.keys())

ans=dic[0]
if ans == 0:
    for i in range(1,maxkey): 
        ans=ans*dic[i]**dic[i+1]
    print(ans%MOD)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
lim = 998244353
N=int(input())
D = list(map(int, input().split()))
E = [abs(i-D[0]) for i in D[1:]]
d = dict(Counter(E))
sum_=1
temp=1
max_n=max(d.keys())
if len(d) ==1:
    print(0)
    sys.exit()
for i in range(1,max_n+1):
    try:
        add = (temp ** d[i]) % lim
        sum_ = (sum_ * add) % lim
        temp = d[i]
    except:
        print(0)
        sys.exit()
print(sum_)

Submission status: Wrong Answer

Solution code:
from collections import Counter
mod=998244353
N=int(input())
D=Counter(list(map(int,input().split())))
l=len(D)

ans=1
for i in range(l):
  if i==0:
    if D[i]!=1:
      print(0)
      exit()
  else:
    if D[i]==0:
      print(0)
      exit()
    else:
      ans=(ans*((D[i-1]**D[i])%mod))%mod
print(ans%mod)

Submission status: Wrong Answer

Solution code:
# B - Counting of Trees
from collections import Counter
N = int(input())
D = list(map(int, input().split()))

ans = 1
if D[0] > 0:
    print(0)
    exit()
else:
    for i in range(1,len(D)):
        if D[i] == 0:
            pass
        else:
            ans *= D[i]
            ans = ans % 998244353
print(ans)

Submission status: Wrong Answer

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

def calc(N, D):
  counts = [0]
  preNum = 0
  for i in D:
    if i == preNum:
      counts[-1] += 1
    elif i == preNum + 1:
      counts.append(1)
    else:
      return 0
    preNum = i
  result = 1
  for i in range(len(counts)-1):
    result = result * pow(counts[i], counts[i+1])
  return result%998244353

print(calc(N, D))

Submission status: Wrong Answer

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
D=many_int()

num=998244353


dicts={}
for d in D:
    if d in dicts:
        dicts[d] += 1
    else:
        dicts[d] = 1

sums = 1
keys = sorted(list(dicts.keys()))

test = [i for i in range(len(keys))]
flg=False
for t,k in zip(test,keys):
    if t!=k:
        flg=True
if flg:
    sums=0

for i in range(len(keys)-1):
    if i >= 1:
        for j in range(dicts[keys[i+1]]):
            sums *= (dicts[keys[i]])
            sums = sums%num
print(sums)

Submission status: Wrong Answer

Solution code:
mod = 998244353
kaizyo = [1, 1]
for i in range(2, 100005):
    kaizyo.append(kaizyo[-1]*i % mod)

# print(kaizyo[:10])


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

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

prime_D = set(D)
prime_D = list(prime_D)
counter = {}

for i in range(len(prime_D)):
    counter[prime_D[i]] = 0

for i in range(len(D)):
    counter[D[i]] += 1  # 数を数えた

counter = sorted(counter.items(), key=lambda x: x[0])

if counter[0][1] > 1:
    print(0)  # 1との距離が0のものがあったらアウト
    exit()

# 距離が2離れているものは定義できない
now = counter[0][0]
for i in range(1, len(counter)):
    if counter[i][0] != (now+1):
        print(0)
        exit()
    now = counter[i][0]

# これですべての例外は弾けた
ans = 1
for i in range(len(counter)):
    ans *= (kaizyo[counter[i][1]] % mod)
    if counter[i][1] == 1 and i > 1:
        ans *= counter[i-2][1]


print(ans % mod)