Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02995 (python)

Fixed submission:
a,b,c,d = map(int,input().split())
u = b - a + 1
from fractions import gcd
cd = c*d//gcd(c,d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd =b//cd - (a-1)//cd
print(int(u - n_c - n_d + n_cd))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
cd = c * d / math.gcd(c, d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
cd = c * d / math.gcd(c, d)
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))
Problem p03061 (python)

Fixed submission:
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))

Buggy submission (verdict: Runtime Error):
from fractions import gcd
import numpy as np
n = int(input())
a = list(map(int, input().split()))
l = np.zeros(n)
r = np.zeros(n+1)
r[n] = 0
for i in range(n):
    if i == 0:
        l[0] = 0
    else:
        l[i] = gcd(l[i-1],a[i-1])
for j in range(n-1, -1, -1):
        r[j] = gcd(r[j+1],a[j])
m = 0
for i in range(n):
    m = max(gcd(l[i],r[i+1]),m)
print(int(m))
Problem p03102 (python)

Fixed submission:
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    eq = c
    for j in range(m):
        eq += a[j] * b[j]
    if eq > 0:
        count += 1
print(count)

Buggy submission (verdict: Runtime Error):
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    eq = c
    for j in range(m):
        eq += a[i] * b[i]
    if eq > 0:
        count += 1
print(count)
Problem p03111 (python)

Fixed submission:
n,A,B,C = map(int,input().split())
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Buggy submission (verdict: Runtime Error):
n,A,B,C = map(int,input().split(()))
l = [int(input()) for i in range(n)]
inf = 10 ** 9

def dfs(i,a,b,c):
    if i == n:
        if min(a,b,c) > 0:
            return abs(a-A) + abs(b-B) + abs(c-C) - 30
        else:
            return inf
    ret0 = dfs(i+1, a, b, c)
    ret1 = dfs(i+1, a + l[i], b, c) + 10
    ret2 = dfs(i+1, a, b + l[i], c) + 10
    ret3 = dfs(i+1, a, b, c + l[i]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))
Problem p03220 (python)

Fixed submission:
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans = 1
temp1 = t - h[0] * 0.006
for i in range(1,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i + 1
        temp1 = temp2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split))
ans = 0
temp1 = t - h[0] * 0.006
for i in range(1,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i
        temp1 = temp2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split))
ans = 0
temp1 = t - h[0] * 0.006
for i in range(a,n):
    temp2 = t - h[i] * 0.006
    if abs(temp1-a) > abs(temp2-a):
        ans = i
        temp1 = temp2
print(ans)
Problem p03239 (python)

Fixed submission:
N,T = map(int,input().split())
min_cost = 10**3 + 1
for i in range(N):
    c, t = map(int,input().split())
    if t <= T and c < min_cost:
        min_cost = c
if min_cost != 10**3 + 1:
    print(min_cost)
else:
    print("TLE")

Buggy submission (verdict: Runtime Error):
N,T = map(int,input().split())
min_cost = 10**3 + 1
for i in range(n):
    c, t = map(int,input().split())
    if t <= T and c < min_cost:
        min_cost = c
if c != 10**3 + 1:
    print(min_cost)
else:
    print("TLE")
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())
ans = 1
if k <= len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        for i in range(len(s)):
            if s[i] != "1":
                ans = int(s[i])
                break
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = 1
if k =< len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        ans = int(s[k-1])
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in range(len(s)):
    if s[i] != "1":
        ans = int(s[i])
        break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
for i in (len(s)):
    if s[i] != "1":
        ans = int(s[i])
        break
print(ans)
Problem p03424 (python)

Fixed submission:
n = int(input())
s = input()
ans = "Three"
for i in range(n):
    if s[i] == "Y":
        ans = "Four"
        break
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = list(map(int, input().split()))
ans = "Three"
for i in range(n):
    if s[i] == "Y":
        ans = "Four"
        break
print(ans)
Problem p03565 (python)

Fixed submission:
s_d = input()
t = input()
if len(s_d) >= len(t):
    for i in range(len(s_d) - len(t), -1, -1):
        possible = True
        for j in range(len(t)):
            if s_d[i + j] == t[j] or s_d[i + j] == "?":
                continue
            else:
                possible = False
                break
        if possible == False:
            continue
        else:
            s = s_d[:i] + t + s_d[i+len(t):]
            for k in range(len(s)):
                if s[k] == "?":
                    s = s[:k] + "a" + s[k+1:]
            break
else:
    possible = False
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_d = input()
t = input()
s = "a"
for i in range(len(s_d) - len(t), -1, -1):
    possible = True
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_d = input()
t = input()
possible = True
for i in range(len(s_d) - len(t), -1, -1):
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_d = input()
t = input()
for i in range(len(s_d) - len(t), -1, -1):
    possible = True
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")
Problem p03597 (python)

Fixed submission:
print(int(input()) ** 2 - int(input()))

Buggy submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
max_a = f // (100*a)
max_b = f // (100*b)
max_c = f // c
max_d = f // d
wat = []
sug = []
for i in range(max_a + 1):
    for j in range(max_b + 1):
        w = 100 * a * i + 100 * b * j
        if w <= f and w > 0:
            wat.append(w)
for i in range(max_c + 1):
    for j in range(max_d + 1):
        s = c*i + d*j
        if s < f:
            sug.append(s)
ans = 0
for x in wat:
    for y in sug:
        if x + y <= f and y <= e * x // 100:
            if ans <= 100 * y // (x + y):
                ans =  100 * y // (x + y)
                out = [x+y, y]
print(*out)
Problem p03625 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
used = [0] * n
a.sort(reverse=True)
x = 0
y = 0
for i in range(1,n):
    if a[i - 1] == a[i] and used[i-1] == 0 and used[i] == 0:
        if x == 0:
            x = a[i]
            used[i] = 1
            used[i-1] = 1
        elif y == 0:
            y = a[i]
            used[i] = 1
            used[i-1] = 1
            break
print(x*y)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
table = {}
for i in range(n):
  if a[i] not in table:
    table[a[i]] = 1
  else:
    table[a[i]] = table[a[i]] + 1
table = sorted(table.items(), key=lambda x: x[1], reverse=True)
x = 0
y = 0
for i in table:
  if table[i] >= 4:
    if x == 0:
      x = i
      y = i
    else:
      y = i
    break
  elif table[i] >= 2:
    if x == 0:
      x = i
    else:
      y = i
      break
print(x*y)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
table = [0] * (10**9 + 1)
for i in range(n):
  table[a[i]] += 1
x = 0
y = 0
for i in range(10**9, 0, -1):
  if table[i] >= 4:
    if x == 0:
      x = i
      y = i
    else:
      y = i
    break
  elif table[i] >= 2:
    if x == 0:
      x = i
    else:
      y = i
      break
print(x*y)
Problem p03645 (python)

Fixed submission:
n, m = map(int, input().split())
g = {}
for _ in range(m):
    a, b = map(int, input().split())
    if a not in g:
        g[a] = [b]
    if b not in g:
        g[b] = [a]
    if a in g:
        g[a].append(b)
    if b in g:
        g[b].append(a)
ans = "IMPOSSIBLE"
for i in g[1]:
    if n in g[i]:
        ans = "POSSIBLE"
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
import numpy as np
g = np.zeros((n+1, n+1))
for _ in range(m):
    a, b = map(int, input().split())
    g[a][b] = 1
    g[b][a] = 1
ans = "IMPOSSIBLE"
for i in range(n+1):
    if g[1][i] == 1:
        if g[i][n] == 1:
            ans = "POSSIBLE"
print(ans)
Problem p03680 (python)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
ans = False
used = set()
i = 1
count = 0
while ans == False:
    count += 1
    if a[i-1] == 2:
        ans = True
    elif i-1 in used:
        break
    else:
        used.add(i-1)
        i = a[i-1]
if ans == True:
    print(count)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
count = 0
i = 0
ans = False
while count < N:
    count += 1
    if a[i] == 2:
        ans = True
        break
    else:
        i = a[i] - 1
if ans == True:
    print(count)
else:
    print("-1")
Problem p03739 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))

def f(a, sgn):
    cnt = 0
    s = 0
    for i in range(n):
        s += a[i]
        sgn *= (-1) #判定する符号は交互に変わる
        if s * sgn <= 0: #sgn一致しなければその積は負
            x = s + sgn*(-1)
            s -= x
            cnt += abs(x)
        
    return cnt
ans = min(f(a, 1), f(a, -1))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a2 = a.copy()

ans1 = 0 #偶数インデックスが正
for i in range(n):
    s1 = sum(a[:i+1])
    if i % 2 == 0:
        if s1 <= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] += x
        else:
            continue
    else:
        if s1 >= 0:
            x = abs(s1) + 1
            ans1 += x
            a[i] -= x
ans2 = 0 #偶数インデックスが負
for i in range(n):
    s2 = sum(a2[:i+1])
    if i % 2 == 1:
        if s2 <= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] += x
        else:
            continue
    else:
        if s2 >= 0:
            x = abs(s2) + 1
            ans2 += x
            a2[i] -= x

print(min(ans1, ans2))
Problem p02922 (python)

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

num = 1

taps = 0

while num < B:
  num -= 1
  num += A
  taps += 1

print(taps)

Buggy submission (verdict: Runtime Error):
A, B = map(int, input())

num = 1

taps = 0

while num < B:
  num -= 1
  num += A
  taps += 1

print(taps)
Problem p02923 (python)

Fixed submission:
N = int(input())
hs = list(map(int, input().split(' ')))
 
now = 0
 
result = 0
count = 0

for i in range(N):
  if hs[i] <= now:
    count += 1
  else:
    result = max(result, count)
    count = 0
  now = hs[i]
result = max(result, count)
 
print(result)

Buggy submission (verdict: Runtime Error):
N = int(input())
hs = map(int, input().split(' '))

now = 0

result = 0

for i in range(N):
  if hs[i] <= now:
    now += 1
  else:
    result = max(result, now)
  now = hs[i]

print(result)
Problem p02946 (python)

Fixed submission:
K, X = map(int, input().split(' '))
print(' '.join([str(i) for i in range(X - (K - 1), (X + K))]))

Buggy submission (verdict: Runtime Error):
K, X = map(int, input().split(' '))
print(' '.join([ for i in range(X - (K + 1), (X + K + 1))]))
Problem p02972 (python)

Fixed submission:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    results = [0]*n
    for i, a in enumerate(reversed(a_s)):
        idx = (n-1) - i
        if sum(results[idx::(idx+1)]) % 2 != a:
            results[idx] = 1
    print(sum(results))
    idxs = [str(i+1) for i, r in enumerate(results) if r == 1]
    if results:
        print(' '.join(idxs))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))
    results = []
    for i, a in enumerate(a_s):
        if a == 1:
            for result in results:
                if (i+1) % result == 0:
                    print(-1)
                    quit() 
            results.append(str(i+1))
    print(len(results))
    if results:
        print(' '.join(results))


if __name__ == '__main__':
    main()
Problem p03160 (python)

Fixed submission:
import sys
input = sys.stdin.readline
N=int(input())
h = list(map(int, input().split()))#[int(input()) for _ in range(N)]
dp=[0]+[abs(h[1]-h[0])]+[10001]*(N-2)

for i in range(2,N):
    dp[i]=min(
        dp[i-1]+abs((h[i]-h[i-1])),
        dp[i-2]+abs((h[i]-h[i-2]))
    )

print(dp[-1])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
N=int(input())
h = [int(input()) for _ in range(N)]
dp=[0]+[abs(h[1]-h[0])]+[10001]*(N-2)

for i in range(2,N):
    dp[i]=min(
        dp[i-1]+abs((h[i]-h[i-1])),
        dp[i-2]+abs((h[i]-h[i-2]))
    )

print(dp[-1])
Problem p03323 (python)

Fixed submission:

A,B= list(map(int, input().split()))

if(A>=9 or B>=9):
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):

A,B= list(map(int, input().split()))

if(A>=9 or b>=9):
    print(":(")
else:
    print("Yay!")

Buggy submission (verdict: Runtime Error):

A,B= input().split()

if(A>=9 or b>=9):
    print(":(")
else:
    print("Yay!")
Problem p03043 (python)

Fixed submission:
import math
n, k = map(int, raw_input().split())
p = 0.0
for i in range(1,n+1):
    if i < k:
        x = math.ceil(math.log((float(k) / float(i)), 2))
        p += (float(1) / float(n)) * ((0.5) ** x)
    else:
        p += (float(1) / float(n))

print p

Buggy submission (verdict: Runtime Error):
import math
n, k = map(int, input().split())
p = 0.0
for i in range(1,n+1):
    if i < k:
        x = math.ceil(math.log((float(k) / float(i)), 2))
        print "---"
        print x
        print i * (2 ** x)
        p += (float(1) / float(n)) * ((0.5) ** x)
    else:
        p += (float(1) / float(n))

print p
Problem p03280 (python)

Fixed submission:
l = input().split()
A = int(l[0])
B = int(l[1])

total = A * B
michi = A + B - 1
hatake = total - michi


print(hatake)

Buggy submission (verdict: Runtime Error):
l = input().split()
num_city    = int(l[0])
num_train   = int(l[1])
num_qa      = int(l[2])


str_train = []
end_train = []
for i in range(num_train):
    l = input().split()
    dist = 0
    str_train.append( int(l[dist]) )
    dist = 1
    end_train.append( int(l[dist]) )

str_qa = []
end_qa = []

for i in range(num_qa):
    l = input().split()
    dist = 0
    str_qa.append( int(l[dist]) )
    dist = 1
    end_qa.append( int(l[dist]) )




S_str = []
s = {}
for i in range(num_city + 1):
    S_str.append(s)

for i in range(num_qa):
    str_v = str_qa[i]
    for j in range(0,str_v + 1):
        S_str[j].add(str_v)

S_end = []
s = {}
for i in range(num_city + 1):
    S_end.append(s)

for i in range(num_qa):
    end_v = end_qa[i]
    for j in range(end_v , num_city + 1):
        S_end[j].add(end_v)

for i in range(0,num_qa):
    str_v = str_qa[i]
    s1 = S_str[ str_v ]

    end_v = end_qa[i]
    s2 = S_end[ end_v ]

    s_intersection = s1 & s2

    print(len(s_intersection))
Problem p03106 (python)

Fixed submission:
A, B, K = [int(i) for i in input().split()]
result_list = []

def divisor_list(n):
    i = 1
    array = []
    while i * i <= n:
        if n % i == 0:
            array.append(i)
            array.append(n//i)
        i += 1
    array = list(set(array))
    return array

for i in divisor_list(A):
    for j in divisor_list(B):
        if i == j:
            result_list.append(i)

print(sorted(result_list)[-K])

Buggy submission (verdict: Runtime Error):
import sympy

A, B, K = [int(i) for i in input().split()]
result_list = []

for i in sympy.divisors(A):
    for j in sympy.divisors(B):
        if i == j:
            result_list.append(i)

print(result_list[-K])

Buggy submission (verdict: Runtime Error):
import sympy

A, B, K = [int(i) for i in input().split()]
result_list = []

for i in sympy.divisors(A):
    for j in sympy.divisors(B):
        if i == j:
            result_list.append(i)

print(result_list[-K])

Buggy submission (verdict: Runtime Error):
import sympy

A, B, K = [int(i) for i in input().split()]
result_list = []

for i in sympy.divisors(A):
    for j in sympy.divisors(B):
        if i == j:
            result_list.append(i)

print(result_list[-K])
Problem p03061 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
    
list_gcd = [(gcd(A[0],A[1]),False),(A[0],True),(A[1],True)]
#print(list_gcd)

for i in range(2,len(A)):
    next_gcd = []
    for j in list_gcd:
        if j[1]:
            this_gcd = (gcd(j[0],A[i]),True)
            if not(this_gcd in next_gcd):
                next_gcd.append(this_gcd)
        else:
            this_gcd = (gcd(j[0],A[i]),False)
            if not(this_gcd in next_gcd):
                next_gcd.append(this_gcd)
                
            this_gcd = (j[0],True)
            if not(this_gcd in next_gcd):
                next_gcd.append(this_gcd)
    list_gcd = next_gcd
    #print(list_gcd)
         
out = 1
for i in list_gcd:
    if i[0] > out:
        out = i[0]
        
print(out)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
A = [int(x) for x in input().split()]

def GCD(numbers):
    x = numbers[0]
    for i in range(1,len(numbers)):
        x = math.gcd(x,numbers[i])
    
    return x

out = 0
for i in range(len(A)):
    l = A[:i] + A[i+1:]
    this_gcd = GCD(l)
    if this_gcd > out:
        out = this_gcd
        
print(out)
Problem p02865 (python)

Fixed submission:
N = int(input())
ans=0
if N%2==0:
    ans=N/2-1
elif N!=1:
    ans=N/2
print(int(ans))

Buggy submission (verdict: Runtime Error):

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=[0] * (M + 1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif M<2:
    print(1)
    sys.exit()

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

for i in range(2,M+1):
        ans *= countlist[i-1]**countlist[i]

print(ans%998244353)

Buggy submission (verdict: Runtime Error):

import sys
import numpy as np
N = int(input())
D = list(map(int,input().split()))
M = max(D)
countlist=np.zeros(M+1)
ans=1

for i in D:
    countlist[i]+=1

if countlist[0]!=1 :
    print(0)
    sys.exit()
elif countlist[1]==0 and M==1:
    print(1)
    sys.exit()

for i in range(2,M+1):
    if countlist[i]>0:
        ans *= countlist[i-1]**countlist[i]
    elif i<M:
        ans=0
    else:
        break


print(int(ans%998244353))

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
D = list(map(int,input().split()))
ans=0

if D.count(0)!=1 :
    print(ans)
    sys.exit()
else:
    ans=1

for i in range(2,99999):
    mae=D.count(i-1)
    ato=D.count(i)

    if ato>0:
        ans *= mae**ato
    elif ato==0 and i<max(D):
        ans=0
    else:
        break
    
    ans%998244353


print(ans%998244353)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
D = list(map(int,input().split()))
ans=0

if D.count(0)==0 :
    print(ans)
    sys.exit()
else:
    ans=1

for i in range(2,99999):
    mae=D.count(i-1)
    ato=D.count(i)

    if ato>0:
        ans *= mae**ato
    elif ato==0 and i<max(D):
        ans=0
    else:
        break

print(ans%998244353)