Problem:


Score : 300 points

Problem Statement

Given is an integer sequence D_1,...,D_N of N elements. Find the number, modulo 998244353, of trees with N vertices numbered 1 to N that satisfy the following condition:

For every integer i from 1 to N, the distance between Vertex 1 and Vertex i is D_i.

Notes

A tree of N vertices is a connected undirected graph with N vertices and N-1 edges, and the distance between two vertices are the number of edges in the shortest path between them.

Two trees are considered different if and only if there are two vertices x and y such that there is an edge between x and y in one of those trees and not in the other.

Constraints

1 \leq N \leq 10^5

0 \leq D_i \leq N-1

Input

Input is given from Standard Input in the following format:

N
D_1 D_2 ... D_N

Output

Print the answer.

Sample Input 1

4
0 1 1 2

Sample Output 1

2

For example, a tree with edges (1,2), (1,3), and (2,4) satisfies the condition.

Sample Input 2

4
1 1 1 1

Sample Output 2

0

Sample Input 3

7
0 3 2 1 2 2 1

Sample Output 3

24



Sample input:
4
0 1 1 2


Sample output:
2

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n or 2**i<s:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            if D[i] - previous_num != 1:
                print(0)
                sys.exit()
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
            
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum%998244353)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(co(map(int,input().split())).items()))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(map(list,co(map(int,input().split())).items())))
#if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(map(list,co(map(int,input().split())).items())))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
#if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=sorted(list(map(list,co(map(int,input().split())).items())))
if l[0][0]==0 and l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:
    ans*=(pre**s)
    ans%=998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=list(map(list,co(map(int,input().split())).items()))
if l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  if i>1:ans*=(pre**s)%998244353
  pre=s
print(ans) if len(l)>=3 else print(1)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=list(map(list,co(map(int,input().split())).items()))
if l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  ans*=(pre**s)%998244353
  pre=s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter as co
n=int(input())
l=list(map(list,co(map(int,input().split())).items()))
if l[0][-1]>1:print(0);exit()
ans=1;pre=1
for i,(n,s) in enumerate(l):
  if i!=n:print(0);exit()
  ans*=(pre**s)%998244353
  pre=s
print(ans) if len(l)>=3 else print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
cnt = [0]*n
for i in a:
    cnt[i] += 1

output = 1
if a[0] != 0:
    print(0)
elif max(a) == 1:
    print(1)
else:
    for i in range(2, n):
        output *= cnt[i-1]**cnt[i]
        output %= 998244353
    print(output)

Submission status: Wrong Answer

Solution code:
import collections

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

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

jug = True

if c[0][0] != 0:
    jug = False

ans = 1

for i in range(1, len(c)):
    if c[i][0] < 0:
        jug == False
    m = c[i-1][1]
    r = c[i][1]
    ans *= m ** r
    
if jug == False:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0 or 0 in D[1:]:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            if D[i] - previous_num != 1:
                print(0)
                sys.exit()
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0 or 0 in D[1:]:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0:
    print(0)
else:
    nums = []
    previous_num = D[0]
    previous_cnt = 1
    cnt = 1
    sum = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            sum *= previous_cnt ** cnt
            previous_cnt = cnt
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            sum *= previous_cnt ** cnt
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if D[0] != 0:
    print(0)
else:
    nums = []
    previous_num = D[0]
    cnt = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            nums.append(cnt)
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            nums.append(cnt)

    sum = 1
    for i in range(2,len(nums)):
        sum *= nums[i-1] ** nums[i]
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
if 0 in D:
    print(0)
else:
    nums = []
    previous_num = D[0]
    cnt = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            nums.append(cnt)
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            nums.append(cnt)

    sum = 1
    for i in range(2,len(nums)):
        sum *= nums[i-1] ** nums[i]
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
print(D)
if D[0] != 0:
    print(0)
else:
    nums = []
    previous_num = D[0]
    cnt = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            nums.append(cnt)
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            nums.append(cnt)

    print(nums)

    sum = 1
    for i in range(2,len(nums)):
        sum *= nums[i-1] ** nums[i]
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = input().split(' ')
for i in range(N):
    D[i] = int(D[i])
D.sort()
print(D)
if D[0] != 0:
    print(0)
else:
    nums = []
    previous_num = D[0]
    cnt = 1
    for i in range(1,N):
        if D[i] != previous_num:
            previous_num = D[i]
            nums.append(cnt)
            cnt = 1
        else:
            cnt += 1
        if i == N-1:
            nums.append(cnt)

    print(nums)

    sum = 1
    for i in range(1,len(nums)):
        sum *= nums[i-1] ** nums[i]
    
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]

num_dict = {}
ans = 1

for i in range(N):
  num_dict[D[i]] = num_dict.get(D[i],0) + 1

if num_dict.get(0) == None or num_dict.get(0) > 1:
  ans = 0
else:
  for i in range(1,len(num_dict)):
    if num_dict.get(i) == None:
      ans = 0
      break
    else:
      ans *= num_dict.get(i-1) ** num_dict.get(i)
      ans %= 998244353

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]

num_dict = {}
ans = 1

for i in range(N):
  num_dict[D[i]] = num_dict.get(D[i],0) + 1

if num_dict.get(0) == None or num_dict.get(0) > 1:
  ans = 0
else:
  for i in range(1,len(num_dict)):
    if num_dict.get(i) == None:
      ans = 0
      break
    else:
      ans *= (num_dict.get(i-1) ** num_dict.get(i))%998244353

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]

num_dict = {}
ans = 1

for i in range(N):
  num_dict[D[i]] = num_dict.get(D[i],0) + 1

if num_dict.get(0) == None or num_dict.get(0) > 1:
  ans = 0
else:
  for i in range(1,len(num_dict)):
    if num_dict.get(i) == None:
      ans = 0
      break
    else:
      ans *= num_dict.get(i-1) ** num_dict.get(i)

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
N = int(input())
D = [int(i) for i in input().split()]

num_dict = {}
ans = 1

for i in range(N):
  num_dict[D[i]] = num_dict.get(D[i],0) + 1

if num_dict.get(0) == None:
  ans = 0
else:
  for i in range(1,len(num_dict)):
    if num_dict.get(i) == None:
      ans = 0
      break
    else:
      ans *= num_dict.get(i-1) ** num_dict.get(i)

print(ans%998244353)

Submission status: Wrong Answer

Solution code:
# nikkei2019-2-qualB - Counting of Trees
from collections import Counter
from functools import reduce


def main():
    N, *D = map(int, open(0).read().split())
    MOD = 998244353
    cnt = Counter(D)
    if D[0] != 0 or cnt[0] > 1:
        ans = 0
    else:
        mul = lambda x, y: (x * cnt[y - 1]) % MOD if cnt[y - 1] else x
        ans = reduce(mul, D)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# nikkei2019-2-qualB - Counting of Trees
from collections import Counter
from functools import reduce


def main():
    N, *D = map(int, open(0).read().split())
    MOD = 998244353
    cnt = Counter(D)
    if D[0] != 0 or cnt[0] > 1:
        ans = 0
    else:
        mul = lambda x, y: (x * cnt[y - 1]) % MOD if cnt[y - 1] else x
        ans = reduce(mul, D[1:])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# nikkei2019-2-qualB - Counting of Trees
from functools import reduce


def main():
    N, *D = map(int, open(0).read().split())
    MOD = 998244353
    cnt = [0] * N
    for i in D:
        cnt[i] += 1
    if D[0] != 0 or cnt[0] > 1:
        ans = 0
    else:
        ans = reduce(lambda x, y: (x * cnt[y - 1]) % MOD, D[1:])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
num=[0]*n
for i in range(n):
       num[i]=d.count(i)
       ans=0
for i in range(n):
       if num[i]==0:
           break
       if i==0:
           ans+=1
       else:
           ans = ans*(num[i-1]**num[i])//998244353


print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    while n > 1:
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p; i += 1
  except:
    pass
print((r, 0)[n > 1])

Submission status: Wrong Answer

Solution code:
n=int(input())
d=list(map(int,input().split()))
num=[0]*n
for i in range(n):
       num[i]=d.count(i)
       ans=0
for i in range(n):
       if num[i]==0:
           break
       if i==0:
           ans+=1
       else:
           ans*=(num[i-1]**num[i])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    while n > i:
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p; i += 1
  except:
    pass
print((r, 0)[n > 1])

Submission status: Wrong Answer

Solution code:
from collections import Counter

M = 998244353
n = int(input())
a = map(int, input().split())
x, c = next(a), Counter(a)
r = 0
if x == c[0] == 0:
  r = p = 1
  try:
    while i < n:
      x = c.get(i)
      r = r * pow(p, x, M) % M
      p = x; n -= p
  except:
    pass
print((r, 0)[n > 1])

Submission status: Wrong Answer

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

# bucket
lst = [[] for i in range(n)]
ans = 1
sum = 1
P = 998244353
if d[0] != 0:
    print(0)
    quit()
else:
    for i in range(n):
        if d[i] == 0 and i != 0:
            print(0)
            quit()
        lst[d[i]].append(i + 1)

    tmp = len(lst[1])
    for i in range(1, n):
        if len(lst[i]) == 0:
            if sum != n:
                print(0)
                quit()
        sum += len(lst[i])
        if i == 1:
            continue
        ans *= (tmp ** len(lst[i])) % P
        tmp = len(lst[i])
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] != 0:
    print(0)
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print(1)
    exit()
if not (2 in array) or not (1 in array):
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] != 0:
    print(0)
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print(1)
    exit()
if not (2 in array):
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] != 0:
    print(0)
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print(1)
    exit()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 1 in array and len(set(array[1:])) == 1:
    print(1)
    exit()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 2 in array:
    pass
else:
    print(0)
    exit()
if len(set(array)) == 2:
    print(1)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
if ans == 0:
    print(1)
    exit()
print(ans)

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

cnt=[0]*(max(D)+1)
mod=998244353
for i in D:
    cnt[i]+=1
if cnt[0]==0:
    print(0)
    exit(0)
ans=1
for i in range(1,len(cnt)):
    if cnt[i]==0:
        print(0)
        exit()
    ans*=pow(cnt[i-1],cnt[i],mod)
    ans%=mod
print(ans)

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

cnt=[0]*(max(D)+1)

mod=998244353
for i in D:
    cnt[i]+=1
ans=1
for i in range(1,len(cnt)):
    if cnt[i]==0:
        print(0)
        exit()
    ans*=pow(cnt[i-1],cnt[i],mod)
    ans%=mod
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first != array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        if first == array[i+1] - 1:
            print(0)
            exit()
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
array = list(map(int, input().split()))
if array[0] == 1:
    print(0)
    exit()
array.sort()
if 2 in array:
    pass
else:
    print(0)
    exit()
index = array.index(2)
count = 1
count_old = array.count(1)
ans = 1
first = array[index]
for i in range(index,N-1):
    if first != array[i+1]:
        ans *= count_old ** count
        count_old = count
        count = 1
    else:
        count += 1
    first = array[i+1]
    ans %= 998244353
ans *= count_old ** count
ans %= 998244353
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

from collections import Counter

# a = comb(n, r)

# import pow

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 998244353
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ds = LI()
    c = Counter(ds)
    max_ = max(ds)
    ans = 1
    before = 1
    if c.get(0) != 1:
        print(0)
        return

    for i in range(max_ + 1):
        if i not in c:
            print(0)
            return
        now = c.get(i)
        ans *= pow(before, now, MOD)
        ans = ans % MOD
        before = now
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
D = [int(i) for i in input().split()]
if sorted(list(set(D))) != [i for i in range(max(D)+1)]:
    print(0)
elif 0 in D and D.count(0) > 1:
    print(0)
elif 0 in D and D.count(0) == 1:
    ans = 1
    mod = 998244353
    freq = [0 for i in range(max(D)+1)]
    for i in D:
        freq[i] += 1
    
    for i in range(1, max(D)+1):    
        ans = ((ans%mod) * (pow(freq[i-1], freq[i], mod)%mod))
        ans %= mod

    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = [int(i) for i in input().split()]
if sorted(list(set(D))) != [i for i in range(max(D)+1)]:
    print(0)
elif 0 in D and D.count(0) > 1:
    print(0)
elif 0 in D and D.count(0) == 1:
    ans = 1
    mod = 998244353
    # (freq[i]-1)C(freq[i-1]-1)
    freq = [0 for i in range(max(D)+1)]
    for i in D:
        freq[i] += 1
    
    
    for i in range(1, max(D)+1):
        
        ans *= pow(freq[i-1], freq[i], mod)
        ans %= mod
    print(ans)

'''
2 2 2

'''

Submission status: Wrong Answer

Solution code:
def main():
    MOD = 998244353
    N = int(input())
    D = [int(i) for i in input().split()]
    if D[0] != 0:
        return print(0)
    from collections import Counter
    c = Counter(D)
    ans = 1
    for d in D:
        if d == 0 or d == 1:
            continue
        else:
            if c[d-1] == 0:
                return print(0)
            ans *= c[d-1]
            ans %= MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not d[0] == 0:
    print(0)
else:
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                sys.exit()
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

if lin[0][0] == 0 or lin[0][1] == 1:
    point = 1
    for i in range(1,len(lin)):
        if lin[i-1][0]+1 != lin[i][0]:
            print(0)
            exit()
        point *= (lin[i-1][1]**lin[i][1])
    print(point%998244353)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10**5+100)]
ans = 1
mx = -1
for i in d:
    lis[i] += 1
    if i > mx:
        mx = i
if lis[0] != 1 or d[0] != 0:
    print(0)
for i in range(1, mx+1):
    ans *= lis[i-1]**lis[i]
print(ans%998244353)

Submission status: Wrong Answer

Solution code:
import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
        sys.exit()
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                sys.exit()
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

lin.sort()

if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Submission status: Wrong Answer

Solution code:
import sys
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
        sys.exit()
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= idx[i-1]**idx[i]%M
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
 
li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))


if lin[0][0] != 0 or lin[0][1] > 1:
    print(0)
    exit()

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    elif lin[i][1] == 0:
        print(0)
        exit()
    point *= (lin[i-1][1]**lin[i][1])

print(point%998244353)

Submission status: Wrong Answer

Solution code:
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i])%M
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
n = int(input())
D = [int(i) for i in input().split()]
if sorted(list(set(D))) != [i for i in range(max(D)+1)]:
    print(0)
elif 0 in D and D.count(0) > 1:
    print(0)
elif 0 in D and D.count(0) == 1:
    ans = 1
    mod = 998244353
    for i in D:
        if i==0:
            continue
        ans *= i
        ans %= mod
    print(ans)

Submission status: Wrong Answer

Solution code:
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    if n == 1:
        print(1)
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i]%M)
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import bisect
from itertools import groupby
import collections
 
n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()
lin = []

for key, value in groupby(li):
    lin.append((key,len(list(value))))

point = 1
for i in range(1,len(lin)):
    if lin[i-1][0]+1 != lin[i][0]:
        print(0)
        exit()
    point *= lin[i-1][1]**lin[i][1]

if lin[0][0] == 0 or lin[0][1] ==1:
    print(point%998244353)
    exit()
else:
    print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10*5+100)]
ans = 1
if lis[0] != 1 or d[0] != 0:
    print(0)
else:
    mx = -1
    for i in d:
        lis[i] += 1
        if i > mx:
            mx = i
    for i in range(1, mx+1):
        for j in lis[i]:
            ans *= lis[i-1]
    print(ans%998244353)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=1
if a[0]!=0:
  print(0)
else:
  b=[1]
  for i in range(1,max(a)+1):
    count=count*(b[i-1]**a.count(i))
    b.append(a.count(i))
  print(count)

Submission status: Wrong Answer

Solution code:
M = 998244353

n = int(input())
d = list(map(int, input().split()))
idx = [0]*n
ans = 1
for i in range(n):
    idx[d[i]] += 1

if not idx[0] == 1:
    print(0)
else:
    for i in range(1,n):
        if idx[i-1] == 0:
            if not idx[i] == 0:
                print(0)
                break
        else:
            ans *= (idx[i-1]**idx[i]%M)
    else:
        print(ans%M)

Submission status: Wrong Answer

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
x=1
if listx[0]!=0:
  x=0
else:
  for i in range(listx[-1]):
    x*=listx.count(int(i+1))+1
print(x)

Submission status: Wrong Answer

Solution code:
n=int(input())
listx=list(map(int,input().split()))
listx.sort()
x=1
if listx[0]!=0:
  x=0
else:
  for i in range(listx[-1]):
    print(i+1)
    x*=listx.count(int(i+1))+1
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = list(map(int, input().split()))
lis = [0 for i in range(10*5+100)]
ans = 1
if lis[0] != 1:
    print(0)
else:
    for i in d:
        lis[i] += 1
    for i in range(1, len(lis)):
        for j in lis[i]:
            ans *= lis[i-1]
    print(ans%998244353)