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 functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    ans = 1
    for i in range(len(C) -1):
        ans *= ((C[i] % 998244353) ** C[i+1]) % 998244353
    
    print(ans % 998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
#d1 = sorted(d)
dic = {i: d.count(i) for i in range(max(d)+1)}
#m = max((i for i in dic))
def f(n):
	if n == 1:
		return 1
	else:
		return n*f(n-1)
if d[0] != 0:
	print(0)
else:
	if all(dic[i]>0 for i in range(max(d))):
		res = 1
		for i in range(1, max(d)+1):
			res *= 2**dic[i-1]*dic[i]
		print(res)
	else:
		print(0)

Submission status: Wrong Answer

Solution code:
import collections

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

d.sort()
e = collections.Counter(d)
e = e.most_common()
e =list(e)
e.sort()



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

Submission status: Wrong Answer

Solution code:
def main():
    import collections
    import sys
    input = sys.stdin.readline
    n = int(input())
    d = list(map(int, input().split()))
    ans = 1
    tmp = -1
    if d[0] != 0:
        print(0)
    else:
        c = collections.Counter(d)
        if 0 in c.keys() and c[0] > 1:
            print(0)
            exit()
        for i in range(1, n):
            if i in c.keys():
                if i == 1:
                    ans *= c[1]
                else:
                    ans = (ans ** c[i]) * c[i]
                ans %= 998244353
            else:
                tmp = i
                break
        for i in range(tmp + 1, n):
            if i in c.keys():
                print(0)
                exit()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def ruijo(a, b, mod):
    x = 1    
    for i in range(b):
        x = ((x%mod) * (a%mod)) % mod     
    return x

x = [0] * (max(D)+1)
for i in range(N):
    x[D[i]] = (x[D[i]]+1)

Sum = 1

for i in range(len(x)):

    if i != 0:
        Sum = (Sum * ruijo(x[i - 1], x[i], 998244353))%998244353
    else:
        Sum = (Sum * (x[i]%998244353))%998244353

print(Sum%998244353)

Submission status: Wrong Answer

Solution code:
N=int(input())
D=list(map(int,input().split()))
C=[0]*N
for i in range(N):
    C[D[i]]+=1
ans=1
rest=0
if D[0]>0:
    print(0)
else:
    for j in range(2,max(D)+1):
        if C[j-1]==1:
            continue
        else:
            ans*=C[j-1]*C[j]
            rest+=(C[j-1]-1)*C[j]
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from operator import mul
from functools import reduce
import itertools

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def combinations_with_replacement_count(n, r):
    return combinations_count(n + r - 1, 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:
                temp_ans_list = [i for i in range(before_num)]
                ans *= len(list(itertools.product(temp_ans_list, repeat = 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 = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(N)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    res *= new_l[n]**new_l[n+1]
print(res%998244353)

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

    if c[0] == N:
        print(0)
        exit()

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()

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()

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

if dict_d[0] == 1:
    pass
else:
    print(0)
    exit()

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:
import math

n = int(input())
Ds = list(map(int, input().split()))
Dsi = [[Ds[i], i+1] for i in range(n)]
length = max(Ds) + 1
Pts = list()

Dsi = sorted(Dsi)
print(Dsi, 'Dsi', 'Ds', Ds)


start = 0
Iss = list()
for i in range(length):
    Is = list()

    #距離がiであるようなヤツを探す
    for j in range(start, length+1):

        print(i, j)
        if Dsi[j][0] == i:
            Is.append(Dsi[j][1])
        else:
            start = j-1
            break

    
    Iss.append(Is)

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


for i in range(len(Iss)):
    if i == 0:
        Pts.append(math.factorial(len(Iss[i])))
    else:
        m = len(Iss[i])
        n = len(Iss[i-1])
        if m < n or m <= 1 or n <= 1:
            Pts.append(m**n * Pts[i-1])

            print(i, Pts[i], 'bbb', m, n)
        else:
            st_p = permutations_count(m - 1, n-1) 
            r_p  = math.factorial(m) * math.factorial(n)

            Pts.append(st_p * r_p * Pts[i-1])
            
            print(i, Pts[i], 'aaa', m, n)
print(Pts)
print('iss', Iss)

Submission status: Wrong Answer

Solution code:
import numpy as np
import time

n = int(input())
L = [int(i) for i in input().split()]
LL = np.zeros(pow(10,5)+1, dtype="object")
LLL = np.array([1 for i in range(pow(10,5)+1)], dtype="object")
T = np.array([int(i) for i in range(pow(10,5)+1)], dtype="object")

for i in range(n):
  LL[L[i]] += 1

LLL = T**LL
LLL[0] = 1
out = 1  

for i in range(len(LLL)):
  out *= LLL[i]
  out = out % 998244353

if L[0] != 0 or L.count(0) != 1:
  out = 0
print(out)

Submission status: Wrong Answer

Solution code:

N = int(input())
D = list(map(int, input().split()))
num = 1
for i in range(1,N):
    if D.count(i) is 0:
        print(0)
        exit()
    num *= D.count(i-1)**D.count(i)

print(num)

Submission status: Wrong Answer

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

ans=1
li2=[1] #最短経路iの頂点の個数を入れるリスト

if min(d)>0:
  print(0)
  exit()
else:
  for i in range(1,n):
    li=[ j for j in d if i == j ]
    length = len(li) #最短経路iの頂点の個数
    if length == 0:
      print(ans % 998244353)
      exit()
    else:
      ans = ans * (li2[-1] ** length)
      li2 += [length]
print(ans % 998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int,input().split()))
li = []
d.sort()
cnt = 0
ans = 1
b = 0
if d[0] != 0:
  print("0")
elif d[1] == 0:
  print("0")
else:
  for i in range(1,n-1):
    if d[i] == d[i+1]:
      if d[i] != len(li)+1:
        b = 1
      cnt += 1
    else:
      if d[i] != len(li)+1:
        b = 1
      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)
  if b == 0:
    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)
  else:
    print("0")

Submission status: Wrong Answer

Solution code:
import numpy as np
import collections
input1 = list(map(int,input().split()))
input2 = list(map(int,input().split()))

N = input1[0]
D = input2

counter = collections.Counter(D)

ans = 1

D.sort()
D_numpy = np.array(D)
if (np.diff(D_numpy)<=1).prod():
  if counter[0] != 1:
    ans = 0
  else:
    for i in range(len(counter)):
      ans *= counter[i]**counter[i+1]
      if ans >= 998244353:
        ans = ans%998244353

else:
  ans = 0

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
D = list(map(int, input().split()))
D.sort()
a=0
c=0
f=1
e=1
end=0
for i in range(n):
  if(D[i]>a+1):
    e=0
    break
  if(D[i]!=a):
    e*=f**c
    f=c
    c=0
    a+=1
  c+=1
  
  if(c>2**a):
    e=0
    break
e*=f**c
print(int(e))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
n=int(input())
d=list(map(int,input().split()))
e=set(d)
f=max(d)
ans=0
ans1=1
c=True
count=[]
for i in range(f+1):
    if i not in e:
        c=False
if d[0]!=0:
    print(ans)
elif c==False:
    print(ans)
else:
    for j in range(n):
        count.append(d.count(j))
    k=1
    while count[k]>0:
        if k==1:
            ans1*=count[k]
        else:
            ans1*=(count[k]+1)*count[k]
        #print(ans1)
        k+=1
ans1=ans1//2
print(ans1%998244353)
#print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(N)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    if new_l[n] == 0:
        continue
    res *= new_l[n]**new_l[n+1]
print(res%998244353)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []
    d = sorted(d)

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for _d in D:
        distance[_d[0]] += 1

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

    if len(distance) != len([i for i in distance if i != 0]):
        print(0)
        return

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            ans = ans * n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ans = 1
for i in d:
    if i != 0:
        ans = (ans * cnt[i-1]) % 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
D = np.array(list(map(int, input().strip().split())))

if D[0] == 0:
    count = [0] * len(D)
    max_d = 0
    for d in D:
        count[d] += 1
        if d > max_d:
            max_d = d

    ans = 1
    for i in range(2,max_d+1):
        if count[i] <= 0:
            ans = 0
            break
        ans *= count[i-1]**count[i]

    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0)

    else:

        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        if len(items) == 1:
            print(0)

        else:
            ans = 1
            tmp = 1
            for i,j in items:
                if i == 0:
                    tmp = j
                    tmp_i = i
                    continue
                
                elif tmp_i+1 != i:
                    ans = 0
                    break

                ans *= tmp**j
                #print(ans)
                tmp = j

            print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import Counter
from functools import reduce
from operator import mul
M = 998244353
N = int(input())
D = list(map(int, input().split()))
counter = set(D)
if D[0] == 0:
    D[0] = 1
    ans = reduce(mul, D)
    for i, k in enumerate(sorted(counter)):
        if i == k:
            continue
        ans = 0
    print(ans % M)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

    C = [0] * (max(D) + 1)
    for d in D:
        C[d] += 1
    # print(C)
    
    ans = 1
    for i in range(len(C) -1):
        if C[i] == 0:
            ans = 0
            break
        ans *= ((C[i] % 998244353) ** C[i+1]) % 998244353
    
    print(ans % 998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
n=int(input())
dlist = list(map(int,input().split()))
c = collections.Counter(dlist)#{0:1,1:3,2:4}
keys = sorted(c.keys())#[0,1,2,4]
max = keys[len(keys)-1]#2
ok = True#check
if c[0] != 1:#1
    ok = False
    print(0)
count = 0
if ok:
    for k in keys:#数字が並んでるか
        #print(str(k)+str(count))
        if count != k:
            print(0)
            ok = False
            break
        count += 1

ans = 1
if ok:
    for i in range(1,max):
        ans = ans*(pow(c[i]%998244353,c[i+1]))
        ans = ans % 998244353
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
ans=1
d.sort()
acount=1
count=1
sd=set(d)
sd=list(sd)
s=0

for i in range(1,n-1):
  if d[i]==d[i+1]:
    acount+=1
  elif d[i]!=d[i+1]:
    ans*=(count**acount)
    count=acount
    acount=1
  
if len(d)>1 and d[-1]!=d[-2]:
  ans*=count
elif len(d)>1 and d[-1]==d[-2]:
  ans*=(count**acount)

  
for i in range(len(sd)-1):
  if sd[i]+1!=sd[i+1]:
    s=1
if s==0:
  if len(d)>1 and d[0]==0 and d[1]!=0:
    print(ans%998244353)
  elif len(d)==1 and d[0]==0:
    print(1)
  elif d[0]!=0:
    print(0)
  else:
    print(0)
else:
  print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
print 0

Submission status: Wrong Answer

Solution code:
#from math import factorial
n = int(input())

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

D.sort()
#print(D)
num = 1
m = 0
flag = 1
mb = 0
A = D[0]
for i in D:
    if i == A:
        mb += 1
    else:
        break
#print(mb)
S = mb

for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
 
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        a = mb ** m
        S *= a
        mb = m
        m = 1
        num += 1
        

    
a = mb ** m
S *= a
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
input = sys.stdin.readline
n = int(input())
d = list( map(int, input().split()) )
MOD = 998244353

c = Counter(d)

def count(c, iter):
    if c[0] != 1:
        return 0

    res = 1
    for i in range(2, iter+2):
        for _ in range(c[i]):
            res *= c[i-1]%MOD
        res %= MOD
    return res%MOD

res = count(c, max(d))
print(res)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
ans = 1
if N == 1 and D[0] == 0:
    print(1)
elif len(set(D))==1:
    print(0)
elif D.count(0) != 1:
    print(0)
else:
    tmp = 1
    cnt = Counter(D)
    #print(cnt)
    flag = True
    for i in range(1,max(D)+1):
        #print(cnt[i],tmp)
        if cnt[i] != tmp:
            flag = False
        c = (tmp**cnt[i]) % mod
        ans *= c % mod
        tmp = cnt[i]
        ans = ans % mod
    if flag:
        print(1)
    else:
        print(ans % mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(N)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    res *= new_l[n]**new_l[n+1]
    if new_l[n+1] == 0:
        break
print(res%998244353)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [int(i) for i in input().split()]
d.sort()
k = [0]*100005
for i in d:
    k[i] += 1
c = 1
for i in range(d[n-1]):
    for j in range(k[i+1]):
        c *= k[i]
        c %= 998244353
if (k[0] >= 2):
    print(0)
else:
    print(c)

Submission status: Wrong Answer

Solution code:
import collections
  
N = int(input())
D = list(map(int, input().split()))
ans = 1
e = 0
  
l = collections.Counter(D)  
 
for i in range(N-1):
  if l[i] != 0:
      ans *= l[i] ** l[i+1]
 
for i in range(N-1):
  if l[i] == 0 and l[i+1] != 0:
    e = 1
     
if D.count(0) != 1 or e == 1:
  print(0)
else:
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
from operator import mul
from functools import reduce
N = int(input())
D = list(map(int, input().split()))
if not D[0]==0:
  ans=0
else:
  D.remove(0)
  ans = reduce(mul, D)
  ans=ans%998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
E = str(input())
l = E.split()
li = [int(s) for s in l]
for i in range(N):
  co = 0
  if li[i] == 0:
    co += 1
    if co > 2 or (li[i]>1 and co == 0):
      print(0)
      break
else:
#  print(li)
  cp = []
  for j in range(N):
    cp.append(0)
    for i in li:
        if i == j:
            cp[i] += 1
 # print(cp)
  ans = 1
  for i in range(2,len(cp)):
    if cp[i] != 0 :
      ans*=cp[i-1]**cp[i]
  print(ans%998244353)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]
#b = [int(i) for i in readline().split()]

wt = [0]*(n+2)
for i in a:
    wt[i] += 1

MOD = 998244353

ans = 1
cnt = 1

#print(wt)

for i,c in enumerate(wt):
    if i == 0:
        if c != 1:
            ans = 0
            break
        else: pass
    else:
        cnt += c
#        print(cnt,c)
        if cnt != n:
            if c == 0:
                ans = 0
                break
            else:
                ans *= pow(wt[i-1],c,MOD)
        else:
            ans *= pow(wt[i-1],c,MOD)
            break
    ans %= MOD    
#    print(i,c,ans,cnt)    

if sum(wt) != n: ans = 0

        
print(ans%MOD)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
N = int(stdin.readline().rstrip())
_A = stdin.readline().rstrip().split()
A = [int(s) for s in _A]
B = []
Max = max(A)
Tes = True
A.sort()

for el in range(Max + 1):
    if (not el in A):
        Tes = False
        break
count = 0
for el in range(0, len(A)):
    count += 1
    if (el == (len(A) - 1)):
        B.append(count)
        break
    if ((not A[el] == A[el + 1])):
        B.append(count)
        count = 0
if (Tes):
    res = 1
    for el in range(1, len(B)):
        res *= B[el - 1] ** B[el]

if (Tes):
    print(res)
else:
    print('0')

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
D = list(map(int, input().split()))
nodes = {}
if D[0] != 0:
  print(0)
  sys.exit()
for i in D:
  v = nodes.get(i, 0)
  nodes[i] = v + 1

prev = 1
ans = 0
for node in nodes.values():
  if ans == 0:
    ans = prev ** node
  else:
    ans *= prev ** node
  prev = node
print(ans)

Submission status: Wrong Answer

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

ans = 1
for i in range(1, d[-1] + 1):
    if i != 0:
        ans *= cnt[i-1] % 998244353
print(ans)

Submission status: Wrong Answer

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

flag = 0
count = 1
max = 0
NUM = [0 for i in range(N)]
 
if D[0] != 0:
    print(0)
    exit()
 
for i in range(N):
    NUM[D[i]] += 1
    if max < D[i]:
        max = D[i]

for h in range(1,N):
    if NUM[h] > 1 and flag == 0:
        flag = h
        break
 
for j in range(flag+1,N):
    NUM[j] += 1
 
 
for k in NUM:
    if k != 0:
        count *= k
 
result = count % 998244353
print(result)

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

    if c[0] > 1:
        print(0)
        exit()

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
lists=list(map(int,input().split()))
anslist=[0 for i in range(n+1)]
anslist.append(0)
for j in lists:
    anslist[j]+=1
if anslist[0]!=1:
    print(0)
else:
    ans=1
    for j in range(n+1):
            for k in range(anslist[j+1]):
                ans=anslist[j]*ans
                ans=ans%(998244353)
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(N)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    if new_l[n+1] == 0:
        break
    res *= new_l[n]**new_l[n+1]
print(res%998244353)

Submission status: Wrong Answer

Solution code:
import numpy as np
import time

n = int(input())
L = [int(i) for i in input().split()]
LL = np.zeros(pow(10,5)+1, dtype="object")
LLL = np.array([1 for i in range(pow(10,5)+1)], dtype="object")
T = np.array([int(i) for i in range(pow(10,5)+1)], dtype="object")

for i in range(n):
  LL[L[i]] += 1

LLL = T**LL
LLL[0] = 1
out = 1  

for i in range(len(LLL)):
  out *= LLL[i]

out = out % 998244353

if L[0] != 0 or L.count(0) != 1:
  out = 0
print(out)

Submission status: Wrong Answer

Solution code:
#from math import factorial
n = int(input())

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

D.sort()
#print(D)
num = 1
m = 0
flag = 1
mb = 0

for i in D:
    if i == D[0]:
        mb += 1
    else:
        break
#print(mb)
S = mb

for i in D:
    if i == 0:
        pass
    elif i == num:
        m += 1
 
    elif i != num:
#        print("NUM",num,"m",m,"MB",mb)
        a = mb ** m
        S *= a
        mb = m
        m = 1
        num += 1
        

    
a = mb ** m
S *= a
print(S % 998244353)
        
#998244353

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import os
import math
import sys
from math import factorial
input = sys.stdin.readline


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル


def cmb(n, r, mod):
    return factorial(n) / factorial(r) / factorial(n - r)
    # if (r < 0 or r > n):
    #     return 0
    # r = min(r, n-r)
    # return g1[n] * g2[r] * g2[n-r] % mod


def main():
    N = int(input())
    d = list(map(int, input().split()))
    D = []
    d = sorted(d)

    for (k, v) in enumerate(d):
        D.append((v, k+1))

    distance = [0] * (max(d) + 1)

    for _d in D:
        distance[_d[0]] += 1

    if min(d) != 0:
        print(0)
        return

    if len(distance) != len([i for i in distance if i != 0]):
        print(0)
        return

    ans = 1
    for i in range(0, len(distance)):
        if i == 0:
            ans = 1
            # print(ans)
        else:
            n = distance[i-1]
            r = distance[i]
            ans = ans * n ** r
            ans = ans % MOD
            # print(ans)

    print(ans)
    # print(*distance)
    # n = 2
    # r = 3
    # print(cmb(n+r-1, r-1, MOD))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    n = int(input())
    d = list(map(int, input().split()))
    
    if d[0] != 0:
        print(0)
        
    else:

        d = sorted(d)
        count = Counter(d)
        #print(count)
        #print(len(count))
        #print(count.keys())
        #print(count.items())

        items = count.items()
        if len(items) == 1:
            print(0)

        else:
            ans = 1
            tmp = 1
            for i,j in items:
                if i == 0:
                    tmp = j
                    continue

                ans *= tmp**j
                #print(ans)
                tmp = j

            print(ans%998244353)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import collections

n=int(input())
d=list(map(int,input().split()))
c = collections.Counter(d)
ans = 1
m=max(d)


for i in range(m):
    ans*=c[i]**c[i+1]
ans = ans%998244353

if c[0]>1:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(x) for x in input().split()]
D = sorted(D)
new_l = [0 for n in range(N)]
ini = D[0]
for n in range(N):
    new_l[D[n]] += 1
res = new_l[0]**new_l[1]
for n in range(1,len(new_l)-1):
    if new_l[n] == 0:
        break
    res *= new_l[n]**new_l[n+1]
print(res%998244353)

Submission status: Wrong Answer

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


def main():
    MOD = 998244353
    N = int(input())
    D = [int(x) for x in input().split()]
    c = collections.Counter(D)
    S_D = sorted(D)

    count = 1
    for i in range(1, max(D) + 1):
        count *= pow(c[i - 1], c[i])

    if count == 1:
        print(0)
        exit()
    print(count % MOD)




    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import heapq

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter 
import sys

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

mod = 998244353
D.sort()
d = list(Counter(D).items()) 

if d[-1][0] != len(d) - 1:
    print(0)
    sys.exit()
if d[0][1] != 1:
    print(0)
    sys.exit()
ans = 1   
for i in range(1,len(d)):
    for _ in range(d[i][1]):
        ans = ((ans * i) % mod)
    
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = tuple(int(i) for i in input().split(' '))
    
counts = [0] * n
for dd in d:
    counts[dd] += 1;
    
if counts[0] == 0:
    print(0)
    exit()
    
for i in range(n-1):
    if (counts[i] == 0 and not counts[i+1] == 0):
        print(0)
        exit()

result = 1;
for i in range(1, n-1):
    result *= pow(counts[i], counts[i+1])
    
print(result)

Submission status: Wrong Answer

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

flag = 0
count = 1
max = 0
NUM = [0 for i in range(N)]
 
if D[0] != 0:
    print(0)
    exit()
 
for i in range(N):
    NUM[D[i]] += 1
    if max < D[i]:
        max = D[i]

for h in range(1,N):
    if NUM[h] > 1 and flag == 0:
        flag = h
        break
 
for j in range(flag,N):
    NUM[j] += 1
 
 
for k in NUM:
    if k != 0:
        count *= k
 
result = count % 998244353
print(result)