Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
num_list = list()
string = input().split()
for i in range(n):
	num_list.append(int(string[i]))
pro = 1
for number in num_list:
	pro *= number
if pro > 10**18:
	pro = -1
print(pro)

Fixed submission:
n = int(input())
num_list = list()
string = input().split()
for i in range(n):
	num_list.append(int(string[i]))
del n
del string
num_list = sorted(num_list)
pro = 1
for number in num_list:
	pro *= number
	if pro > 10**18:
		pro = -1
		break
print(pro)
Buggy python submission (verdict: Runtime Error):
from Decimal import *
n1, n2 = map(Decimal, input().split())
print(int(n1*n2))

Fixed submission:
from decimal import Decimal
n1, n2 = map(Decimal, input().split())
print(int(n1*n2))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

mul = a*b
sub = a-b
add = a+b

print(max(mul,sub,add))

Fixed submission:
a, b = input().split(" ")

a = int(a)
b = int(b)

mul = a*b
sub = a-b
add = a+b

print(max(mul,sub,add))
Buggy python submission (verdict: Time Limit Exceeded):
def countPairs(str_arr):
	count = 0
	for i in range(N):
		for j in range(i+1,N):
			if str_arr[i] == str_arr[j]:
				count += 1
	return count


N = int(input())
str_arr = []

for i in range(N):
	str = input()
	str_arr.append(sorted(str))

print(countPairs(str_arr))

Fixed submission:
import operator as op
from functools import reduce
import math
	

def ncr(n, r):
	if n < r:
		return 0
	else :
		return (math.factorial(n)) / (math.factorial(n-r)*math.factorial(r))

def countPairs(str_arr, N):
	str_cnt = [0]
	str = str_arr[0]
	j = 0
	for i in range(N):
		if(str_arr[i]==str):
			str_cnt[j] += 1
		else:
			str = str_arr[i]
			j += 1
			str_cnt.append(0)
			str_cnt[j] += 1
	count = 0
	for i in range(len(str_cnt)):
		count += ncr(str_cnt[i],2)
	print(int(count))

def main():
	N = int(input())
	str_arr = []
	for i in range(N):
		str = input()
		str_arr.append(sorted(str))
	str_arr = sorted(str_arr)
	countPairs(str_arr, N)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def isAnagram(str_l, str_r):
	if sorted(str_l)==sorted(str_r): 
		return True 
	else:
		return False


def countPairs(str_arr):
	count = 0
	for i in range(N):
		for j in range(i+1,N):
			if isAnagram(str_arr[i], str_arr[j]):
				count += 1
	return count


N = int(input())
str_arr = []

for i in range(N):
	str = input()
	str_arr.append(str)

print(countPairs(str_arr))

Fixed submission:
import operator as op
from functools import reduce
import math
	

def ncr(n, r):
	if n < r:
		return 0
	else :
		return (math.factorial(n)) / (math.factorial(n-r)*math.factorial(r))

def countPairs(str_arr, N):
	str_cnt = [0]
	str = str_arr[0]
	j = 0
	for i in range(N):
		if(str_arr[i]==str):
			str_cnt[j] += 1
		else:
			str = str_arr[i]
			j += 1
			str_cnt.append(0)
			str_cnt[j] += 1
	count = 0
	for i in range(len(str_cnt)):
		count += ncr(str_cnt[i],2)
	print(int(count))

def main():
	N = int(input())
	str_arr = []
	for i in range(N):
		str = input()
		str_arr.append(sorted(str))
	str_arr = sorted(str_arr)
	countPairs(str_arr, N)


main()
Buggy python submission (verdict: Time Limit Exceeded):
_ = input()
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a

ans = ans if ans <= 10 ** 18 else -1
print(ans)

Fixed submission:
_ = input()
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a

    if ans > 10 ** 18:
        break
ans = 0 if 0 in A else ans
ans = ans if ans <= 10 ** 18 else -1
print(ans)

Buggy python submission (verdict: Runtime Error):
_ = input()
A = list(map(int, input().split()))
b = np.prod(A)
b = b if b < 10 ** 18 else -1
print(b)

Fixed submission:
_ = input()
A = list(map(int, input().split()))

ans = 1
for a in A:
    ans *= a

    if ans > 10 ** 18:
        break
ans = 0 if 0 in A else ans
ans = ans if ans <= 10 ** 18 else -1
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B = input().split()


 
print(int(A) * int(B * 100) // 100)

Fixed submission:
A, B = input().split()
print(int(A) * int(B.replace(".", "")) // 100)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
def m(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list

print(m(a), m(b))
list = m(a)+ m(b)
res = [e for e in set(list) if list.count(e) > 1]
print(res[c])

Fixed submission:
a,b,c = map(int, input().split())
def m(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list


list = m(a)+ m(b)
res = [e for e in set(list) if list.count(e) > 1]
res.sort(reverse=True)
print(res[c-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
  
while len(set(s)) == 2:
  
  count += s.count("10")*2
  s = s.replace("10","")
  count += s.count("01")*2
  s = s.replace("01","")

print(count)



Fixed submission:
s = input()
print(min(s.count("0"),s.count("1"))*2)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input())
if b % a == 0:
  print(a+b)
else:print(b-a)
  

Fixed submission:
a, b = map(int, input().split())
if b % a == 0:
  print(a+b)
else:print(b-a)
Buggy python submission (verdict: Time Limit Exceeded):
import re
S = input()
count=0
num=1
while num!=0:
    num=S.count("BW")
    S=re.sub("BW", "WB", S, num)
    count+=num
print(count)



Fixed submission:
S =list(input())
count=0
w_count=0
for i in range(len(S)):
    if S[i]=="W":
        count+=i
        w_count+=1
print(int(count-w_count*(w_count-1)/2))

Buggy python submission (verdict: Time Limit Exceeded):
import re
S = input()
count=0
while True:
    pS=S
    S=re.sub("BW", "WB", S,1)
    if pS==S:
        break
    else:
        count+=1
print(count)


   
   


Fixed submission:
S =list(input())
count=0
w_count=0
for i in range(len(S)):
    if S[i]=="W":
        count+=i
        w_count+=1
print(int(count-w_count*(w_count-1)/2))

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
count=0
num=1
while True:
    num=0
    for i in range(len(S)-1):
        if S[i]=="B" and S[i+1]=="W":
            S[i]="W" 
            S[i+1]="B"
            count+=1
            num+=1
    if num==0:
        break
print(count)


Fixed submission:
S =list(input())
count=0
w_count=0
for i in range(len(S)):
    if S[i]=="W":
        count+=i
        w_count+=1
print(int(count-w_count*(w_count-1)/2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
     print("Hello World")
else:
     A =  int(input())
     B =  int(input())
     print(A+B
     




Fixed submission:
N=int(input())
sum_a=0
if N==1:
    print("Hello World")
else:
    for _ in range(2):
        a=int(input())
        sum_a+=a
    print(sum_a)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=xprint((a-1)*(b-1))

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print((a-1)*(b-1))

Fixed submission:
a,b=map(int,input().split())
print((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
import sympy

N=int(input())
count=0
if N==195:
    print(5)
elif N==189:
    print(4)
elif N==165:
    print(3)
elif N==135:
    print(2)
elif N==105:
    print(1)
else:
    print(0)


Fixed submission:
N=int(input())
count=0
if N>=195:
    print(5)
elif N>=189:
    print(4)
elif N>=165:
    print(3)
elif N>=135:
    print(2)
elif N>=105:
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import sympy

N=int(input())
count=0
for i in range(N):
    if sympy.divisor_count(i+1)==8 and (i+1)%2==1:
        count+=1
    else:
        continue

print(count)


Fixed submission:
N=int(input())
count=0
if N>=195:
    print(5)
elif N>=189:
    print(4)
elif N>=165:
    print(3)
elif N>=135:
    print(2)
elif N>=105:
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import sympy

N=int(input())
count=0
for i in range(N):
    if sympy.divisor_count(i+1)==8 and (i+1)%2==1:
        count+=1

print(count)


Fixed submission:
N=int(input())
count=0
if N>=195:
    print(5)
elif N>=189:
    print(4)
elif N>=165:
    print(3)
elif N>=135:
    print(2)
elif N>=105:
    print(1)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
import sympy

N=int(input())
count=0
for i in range(N):
    if sympy.divisor_count(i+1)==8 and (i+1)%2==1:
        count+=1
input(count)


Fixed submission:
N=int(input())
count=0
if N>=195:
    print(5)
elif N>=189:
    print(4)
elif N>=165:
    print(3)
elif N>=135:
    print(2)
elif N>=105:
    print(1)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
// https://atcoder.jp/contests/arc061/tasks/arc061_a
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  cin >> S;

  ll ans = 0;
  int m = S.size() - 1;

  rep(bit, 1 << m) {
    ll cur = S[0] - '0';
    rep(i, m) {
      if (bit & (1 << i)) {
        ans += cur;
        cur = 0;
      }
      cur = cur * 10 + S[i + 1] - '0';
    }
    ans += cur;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
s = input()
n = len(s) - 1
ans = 0
for bit in range(1 << n):
    now = 0
    for i in range(bit):
        if bit & (1 << i):
            ans += int(s[now : i + 1])
            now = i + 1
    ans += int(s[now : len(s)])
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int), input().split())
S = list(input())
S[K - 1] = S[K - 1].lower()
print(''.join(S))


Fixed submission:
N, K = map(int, input().split())
S = list(input())
S[K - 1] = S[K - 1].lower()
print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
ans = 0
for A in range(1, K+1):
  for B in range(1, K+1):
    a = A
    b = B
    gcd_AB = 0
    while gcd_AB == 0:
      if a > b:
        a = a + b
        b = a - b
        a = a - b # 必ず c <= d になる
      if b%a == 0:
        gcd_AB = a
      else:
        b = b%a
    for C in range(1, K+1):
      c = C
      gcd_ab = gcd_AB
      gcd_ABC = 0
      while gcd_ABC == 0:
        if gcd_ab > c:
          gcd_ab = gcd_ab + c
          c = gcd_ab - c
          gcd_ab = gcd_ab - c # 必ず c <= d になる
        if c%gcd_ab == 0:
          gcd_ABC = gcd_ab
        else:
          c = c%gcd_ab
      ans += gcd_ABC
print(ans)

Fixed submission:
import math

K = int(input())
ans = 0
for A in range(1, K+1):
  for B in range(1, K+1):
    AB = math.gcd(A, B)
    for C in range(1, K+1):
      ans += math.gcd(AB, C)
print(ans)
Buggy python submission (verdict: Runtime Error):
L = int(input().split())

ans = (L/3)**3
print(ans)

Fixed submission:
L = int(input())

ans = (L/3)**3
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 0

for i in range(N):
  if i == 0:
    ans += 1
    continue
  
  if P[i] < min(P[:i]):
    ans += 1

print(ans)

Fixed submission:
N = int(input())

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

ans = 1
minj = 0

for i in range(1, N):
  
  if P[i] < P[minj]:
    ans += 1
    minj = i

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

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

ans = 0

for i in range(N):
  if i == 0:
    ans += 1
    continue
    
  true = 1
  for j in range(i):
    if P[i] > P[j]:
      true = 0
      break
  
  if true == 1:
    ans += 1

print(ans)

Fixed submission:
N = int(input())

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

ans = 1
minj = 0

for i in range(1, N):
  
  if P[i] < P[minj]:
    ans += 1
    minj = i

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

c = [[0 for i in range(9)] for i in range(9)]

for i in range(9):
  for j in range(9):
    for n in range(1, N+1):
      if (n % 10) == j+1 and int(str(n)[0]) == i+1:
        c[i][j] += 1
        
ans = 0
for i in range(9):
  for j in range(9):
    ans = ans + c[i][j]*c[j][i]
print(ans)

Fixed submission:
N = int(input())

c = [[0 for i in range(10)] for i in range(10)]

for n in range(1, N+1):
  i = int(str(n)[0])
  j = n % 10
  c[i][j] += 1

ans = 0
for i in range(10):
  for j in range(10):
    ans = ans + c[i][j]*c[j][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(nput())
S, T = input().split()
ans = ""
for i in range(N):
  ans = ans + S[i:i+1] + T[i:i+1]
  
print(ans)

Fixed submission:
N = int(input())
S, T = input().split()
ans = ""
for i in range(N):
  ans = ans + S[i:i+1] + T[i:i+1]
  
print(ans)
Buggy python submission (verdict: Runtime Error):
# SUN MON TUE WED THU FRI SAT

A = input()

if A == "SUN":
  print(7)
elif A == "MON":
  print(6)
elif A == "TUE":
  prnt(5)
elif A == "WED":
  print(4)
elif A == "THU":
  print(3)
elif A == "FRI":
  print(2)
elif A == "SAT":
  print(1)

Fixed submission:
# SUN MON TUE WED THU FRI SAT

A = input()

if A == "SUN":
  print(7)
elif A == "MON":
  print(6)
elif A == "TUE":
  print(5)
elif A == "WED":
  print(4)
elif A == "THU":
  print(3)
elif A == "FRI":
  print(2)
elif A == "SAT":
  print(1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

ANS = ""

for MOJI in S:
  i = ord(MOJI) + N
  if i > 90:
    i = i - 26
  ANS.append(chr(i))

Fixed submission:
N = int(input())
S = input()

ANS = ""

for MOJI in S:
  i = ord(MOJI) + N
  if i > 90:
    i = i - 26
  ANS = ANS + chr(i)

print(ANS)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

if N % 2 == 1:
  print("No")
else:
  half = N/2
  ans = "Yes"
  for i in range(half):
    if S[i] != S[i+half]:
      ans = "No"
      break
  print(ans)

Fixed submission:
N = int(input())
S = input()

if N % 2 == 1:
  print("No")
else:
  half = int(N/2)
  ans = "Yes"
  for i in range(half):
    if S[i] != S[i+half]:
      ans = "No"
      break
  print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, C = map(int, input().split())

if A-B >= C:
  print(0)
else::
    print(C-A+B)

Fixed submission:
A, B, C = map(int, input().split())

if A-B >= C:
  print(0)
else:
    print(C-A+B)
Buggy python submission (verdict: Runtime Error):
N = int(input())

# 1 <= N <= 10**5 = 100,000

if N <= 9:
  print(N)
elif N <= 999:
  ans = 9 + (N - 99)
  print(ans)
elif N <= 99999:
  ans = 9 + 900 + (N - 9999)
  print(ans)
else:
  print(90909

Fixed submission:
N = int(input())

# 1 <= N <= 10**5 = 100,000

if N <= 99:
  print(min(N, 9))
elif N <= 9999:
  ans = 9 + (min(N, 999) - 99)
  print(ans)
else:
  ans = 9 + 900 + (min(N, 99999) - 9999)
  print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
sl = [*S]

if sl[0]==sl[1] and sl[2]==sl[3] and sl[0]!=sl[2]:
  print("Yes")
elif sl[0]==sl[2] and sl[1]==sl[3] and sl[0]!=sl[1]:
  print("Yes")
elif sl[0]==sl[3] and sl[1]==sl[2] and sl[0]!=sl[1]:
  print("Yes")
else:
  print("No")

Fixed submission:
S = input()
sl = list(S)

if sl[0]==sl[1] and sl[2]==sl[3] and sl[0]!=sl[2]:
  print("Yes")
elif sl[0]==sl[2] and sl[1]==sl[3] and sl[0]!=sl[1]:
  print("Yes")
elif sl[0]==sl[3] and sl[1]==sl[2] and sl[0]!=sl[1]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
S = int(input())

s = list(S)

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")


Fixed submission:
S = input()

s = list(S)

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")

Buggy python submission (verdict: Runtime Error):
s = int(input())

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")

Fixed submission:
S = input()

s = list(S)

if s[0]==s[1] or s[1]==s[2] or s[2]==s[3]:
  print("Bad")
else:
  print("Good")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

L = []
R = []
for i in range(M):
  a, b = map(int, input().split())
  L.append(a)
  R.append(b)

min = min(L)
max = max(R)

ans = max(0, max - min + 1)
print(ans)

Fixed submission:
N, M = map(int, input().split())

L = []
R = []
for i in range(M):
  a, b = map(int, input().split())
  L.append(a)
  R.append(b)

minmin = max(L)
maxmax = min(R)

ans = maxmax - minmin + 1
if ans < 0:
  ans = 0
print(ans)
Buggy python submission (verdict: Runtime Error):
def multi(L):
  ans = 0
  for l in L:
  	if ans <=10**18:
      ans *= l
    else:
      ans = -1
      break
      
   return ans

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

print(multi(A_list))
    

Fixed submission:
 
N = int(input())
A_list = list(map(int, input().split()))

ans = 1
if 0 in A_list:
    ans = 0
else:
    for l in A_list:

        if ans > (10**18):
            ans = -1
            break
        else:
            ans *= l

if ans > (10**18):
    ans = -1
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A_list = list(map(int, input().split()))
out_loop = [1]
flag = [0, 1] + [0]* (N - 1)

for a in A_list:
    if flag[a] == 0:
        out_loop.append(a)
    else:
        loop = out_loop[out_loop.index(a):]
        
if K <= (len(out_loop) - 1):
    print(out_loop[K])
else:
    k = K - len(out_loop) - 1
    k %= len(loop)
    print(loop[k - 1])


Fixed submission:
N, K = map(int, input().split())
A_list = [-1] + list(map(int, input().split()))
out_loop = [1]
flag = [0, 1] + [0]* (N - 1)
a = A_list[1]
while flag[a] == 0:
    out_loop.append(a)
    flag[a] = 1
    a = A_list[a]
    

        
if K <= (len(out_loop) - 1):
    print(out_loop[K])
else:
    loop = out_loop[out_loop.index(a):]
    k = K - (len(out_loop) - 1)
    k %= len(loop)
    print(loop[k - 1])
Buggy python submission (verdict: Runtime Error):
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
d = [[0]*3]*3
for i in range(3):
  for j in range(3):
    b = int(input())
    if A[i][j] == b:
      d[i][j] = 1

ans = "No"

for i in range(3):
  if sum(d[i]) == 3:
    ans = "Yes"
    break
  if sum([D[i] for D in d]) == 3:
    ans = "Yes"
    break
if sum([d[i][i] for i in range(3)]) == 3:
  ans = "Yes"

if sum([d[i][2 - i] for i in range(3)]) == 3:
  ans = "Yes"
  
print(ans)

	
    
  

Fixed submission:
A_list1 = list(map(int, input().split()))
A_list2 = list(map(int, input().split()))
A_list3 = list(map(int, input().split()))

bingo = [A_list1, A_list2, A_list3, [A_list1[0], A_list2[1], A_list3[2]], [A_list1[2], A_list2[1], A_list3[0]], [A_list1[0], A_list2[0], A_list3[0]], [A_list1[1], A_list2[1], A_list3[1]], [A_list1[2], A_list2[2], A_list3[2]]]

N = int(input())

b_list = [int(input()) for _ in range(N)]

ans = "No"
for b in bingo:
    c = 0
    for B in b:
        if B in b_list:
            c += 1
    if c == 3:
        ans = "Yes"
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

S_list = []
S_count = []
ans = set()

for _ in range(N):
    S = input()
    if (S in S_list):
        S_count[S_list.index(S)] += 1
    else:
        S_list.append(S)
        S_count.append(0)

M = max(S_count)

for i, s in enumerate(S_count):
    if s == M:
        ans.add(S_list[i])

ans = sorted(ans)

for a in ans:
    print(a)




Fixed submission:
N = int(input())

S_list = {}
ans = set()

for _ in range(N):
    S = input()
    try:
        S_list[S] += 1
    except KeyError:
        S_list[S] = 0

M = max(S_list.values())
S_list = sorted(S_list.items(), key = lambda x: x[0])

for s, v in S_list:
    if v == M:
        print(s)
Buggy python submission (verdict: Runtime Error):
N = int(input())
MAX_list = []
ans = 0
A = -10**9

for _ in range(N):
    X, L = map(int, input().split())
    MAX_list.append((X + L - 1), (X - L + 1))
MAX_list = sorted(MAX_list)

for m, l in MAX_list:
    if l > A:
        ans += 1
        A = m

print(ans)

Fixed submission:
N = int(input())
MAX_list = []
ans = 0
A = -10**9-2

for _ in range(N):
    X, L = map(int, input().split())
    MAX_list.append(((X + L), (X - L)))
MAX_list = sorted(MAX_list)

for m, l in MAX_list:
    if l >= A:
        ans += 1
        A = m

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K, S = map(int, input())

ans = [S]*K
ans += [S+1]*(N - K)

print(ans)

Fixed submission:
N, K, S = map(int, input().split())

ans = [S]*K
if S == 10**9:
    #最大値の時に制限の値を超えないように
    ans += [1]*(N - K)   
else:
    ans += [S+1]*(N - K)
ans = list(map(str, ans))

print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
mod = 998244353
 
for i, d in enumerate(D):
    if (i == 0) & (d != 0):
        print(0)
        a = 1
        break
    if (i != 0) & (d == 0):
        print(0)
        a = 1
        break
    c[d] += 1


if a == 0:
    for o in range(1, N):
        ans *= c[o]**c[o + 1]

    
    print(ans%mod)


Fixed submission:
N = int(input())
D = list(map(int, input().split()))
c = [0]*(N + 1)
a = 0
ans = 1
temp = 0
pre = 1
mod = 998244353
c = 1

if D[0] != 0:
    print(0)
    a = 1

if a == 0:
    D = sorted(D)
    for i, d in enumerate(D):
        if i == 0:
            continue
        if d == 0:
            print(0)
            a = 1
            break
        if temp != d:
            if (d - temp) != 1:
                print(0)
                a = 1
                break
            ans *= pre ** c

            temp = d
            pre = c
            c = 1
        else:
            c += 1

        if i == N-1:
            ans *= pre ** c
    if a == 0:
        print(ans%mod)