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

Fixed submission:
N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N)

for i in range(1, N):
    if S[i - 1] + S[i] == 'AC':
        cnt[i] = cnt[i - 1] + 1
    else:
        cnt[i] = cnt[i - 1]

for _ in range(Q):
    l, r = map(int, input().split())
    ans = cnt[r - 1] - cnt[l - 1]
    print(ans)

Buggy submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = list(input())
cnt = [0] * (N - 1)

last = ''
for i in range(N):
    c = S[i]
    if (last + c) == 'AC':
        cnt[i] = 1
    last = c

for _ in range(Q):
    l, r = map(int, input().split())
    ans = sum(cnt[l - 1:r - 1])
    print(ans)
Problem p03148 (python)

Fixed submission:
from collections import defaultdict

n, k = map(int, input().split())
top = [0] * n
sub = []

for i in range(n):
    t, d = map(int, input().split())
    t -= 1
    if top[t] == 0:
        top[t] = d
    else:
        if d > top[t]:
            sub.append(top[t])
            top[t] = d
        else:
            sub.append(d)

top.sort(reverse=True)
top_sum = [0]
sub.sort(reverse=True)
sub_sum = [0]

for p in top:
    if p == 0:
        top_sum.append(-1)
    else:
        top_sum.append(top_sum[-1] + p)

for p in sub:
    sub_sum.append(sub_sum[-1] + p)

ans = 0

for i in range(1, k + 1):
    if (len(sub_sum) - 1) >= (k - i) and top_sum[i] != -1:
        ans = max(ans, top_sum[i] + sub_sum[k - i] + i ** 2)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n, k = map(int, input().split())
ans = 0
top = [0] * 10 ** 5
sub = []

for i in range(n):
    t, d = map(int, input().split())
    if top[t] == 0:
        top[t] = d
    else:
        if d > top[t]:
            sub.append(top[t])
            top[t] = d
        else:
            sub.append(d)

top.sort(reverse=True)
top_sum = [0]
sub.sort(reverse=True)
sub_sum = [0]

for p in top:
    if p == 0:
        top_sum.append(-1)
    else:
        top_sum.append(top_sum[-1] + p)

for p in sub:
    sub_sum.append(sub_sum[-1] + p)

ans = 0

for i in range(1, k + 1):
    if (len(sub_sum) - 1) >= (k - i) and top_sum[i] != -1:
        ans = max(ans, top_sum[i] + sub_sum[k - i] + i ** 2)
        
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

n, k = map(int, input().split())
ans = 0
top = [0] * 10 ** 5
sub = []
kinds = 0

for i in range(n):
    t, d = map(int, input().split())
    if top[t] == 0:
        top[t] = d
        kinds += 1
    else:
        if d > top[t]:
            sub.append(top[t])
            top[t] = d
        else:
            sub.append(d)

top.sort(reverse=True)
top = top[:kinds]
top_sum = [0]
sub.sort(reverse=True)
sub_sum = [0]

for p in top:
    top_sum.append(top_sum[-1] + p)

for p in sub:
    sub_sum.append(sub_sum[-1] + p)

ans = 0
start = min(k, len(top_sum) - 1)
end = max(1, k - len(sub_sum) + 1)

for i in range(start, end - 1, -1):
    ans = max(ans, top_sum[i] + sub_sum[k - i] + i ** 2)
print(ans)
Problem p03241 (python)

Fixed submission:
def divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res

n, m = map(int, input().split())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    if nums == []:
        break
    num = nums.pop(0)
print(ans)

Buggy submission (verdict: Runtime Error):
def divisors(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
    return res

n, m = map(int, input().split())
ans = 0
nums = divisors(m)
nums.sort()
num = nums.pop(0)
while num * n <= m:
    if (m - num * n) % num == 0:
        ans = num
    num = nums.pop(0)
print(ans)
Problem p03262 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
for i in range(N):
    diff.append(abs(x[i] - X))

while len(diff) > 1:
    a, b = diff.pop(), diff.pop()
    diff.append(gcd(a, b))

print(diff[0])

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

N, X = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
diff = []
for i in range(0, N - 1):
    diff.append(x[i + 1] - x[i])

if diff:
    ans = gcd_list(diff)
else:
    ans = x[0] - 1

print(ans)
Problem p03282 (python)

Fixed submission:
s = list(map(int, list(str(input()))))
k = int(input())

i = 0
while i + 1 <= k:
    ans = s[i]
    if s[i] != 1:
        break
    i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(map(int, list(str(input()))))
k = int(input())

i = 0
while i <= k:
    ans = s[i]
    if s[i] != 1:
        break
    i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(map(int, list(str(input()))))
k = int(input())

if k == 1:
    ans = s[0]
else:
    if s[0] != 1:
        ans = s[0]
    else:
        i = 0
        while i < len(s):
            i += 1
            ans = s[i]
            if s[i] != 1:
                break
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(map(int, list(str(input()))))
k = int(input())

if k == 1:
    ans = s[0]
if s[0] != 1:
    ans = s[0]
else:
    i = 0
    while i < k:
        i += 1
        ans = s[i]
        if s[i] != 1:
            break
print(ans)
Problem p03475 (python)

Fixed submission:
N = int(input())
params = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N - 1):
    time = 0
    for j in range(i, N - 1):
        c = params[j][0]
        s = params[j][1]
        f = params[j][2]
        if s > time:
            time += s - time + c
        else:
            time += (s - time) % f + c
    print(time)
    
print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]

ans = -(10 ** 7)
stk = []

stk.append([0] * N)

for i in range(10):
    len_stk = len(stk)
    for j in range(len_stk):
        total = 0
        arr = []
        for k in range(N):
            open_cnt = stk[j][k] + f[k][i]
            arr.append(open_cnt)
            total += p[k][open_cnt]
        ans = max(ans, total)
        stk.append(arr)

print(ans)
Problem p03503 (python)

Fixed submission:
N = int(input())
f = [list(map(int, input().split())) for _ in range(N)]
p = [list(map(int, input().split())) for _ in range(N)]

ans = []
stk = []

stk.append([0] * N)

for i in range(10):
    len_stk = len(stk)
    for j in range(len_stk):
        total = 0
        arr = []
        for k in range(N):
            open_cnt = stk[j][k] + f[k][i]
            arr.append(open_cnt)
            total += p[k][open_cnt]
        ans.append(total)
        stk.append(arr)

print(max(ans))

Buggy submission (verdict: Runtime Error):
A, B, X = map(int, input().split())
ans = 0

if (X - B * 10) // A > pow(10, 9):
  ans = pow(10, 9)  
else:
        for i in range(1, 10):
       	    num = (X - i * B) // A
        if i == 10 and num > pow(10, 9):
            ans = pow(10, 9)
        if pow(10, i) > num >= pow(10, i - 1):
            ans = max(ans, num)
        elif num >= pow(10, i):
            ans = max(ans, pow(10, i) - 1)

print(ans)
Problem p03624 (python)

Fixed submission:
import string
s = set(list(input()))
ans = 'None'
for c in string.ascii_lowercase:
    if not c in s:
        ans = c
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import string
s = list(set(list(input())))
s.sort()
comp = string.ascii_lowercase
if len(s) == len(comp):
    ans = 'None'
else:
    for i in range(len(s)):
        if s[i] != comp[i]:
            ans = comp[i]
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import string
s = list(set(list(input())))
s.sort()
comp = string.ascii_lowercase
if len(s) == len(comp):
    ans = 'None'
else:
    for i, j in zip(s, string.ascii_lowercase):
        if i != j:
            ans = j
            break
print(ans)
Problem p03695 (python)

Fixed submission:
N = int(input())
an = list(map(int, input().split()))
over_cnt = 0
colors = []
for a in an:
    rate = a // 400
    if rate >= 8:
        over_cnt += 1
    elif rate not in colors:
        colors.append(rate)

print(max(len(colors), 1), len(colors) + over_cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
an = list(map(int, input().split()))
over_cnt = 0
colors = []
for a in an:
    rate = a // 400
    if rate >= 8:
        over_cnt += 1
    elif rate not in colors:
        colors.append(rate)

min = len(colors)
max = min(len(colors) + over_cnt, 8)
print(min, max)
Problem p03699 (python)

Fixed submission:
n = int(input())
ans = 0
score = []
for _ in range(n):
    score.append(int(input()))

score.sort()
total = sum(score)
if total % 10 == 0:
    for s in score:
        if s % 10 != 0:
            total -= s
            break

print(total if total % 10 != 0 else 0)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
l = 1
r = 10 ** 5
for _ in range(m):
    li, ri = map(int, input().split())
    l = max(l, li)
    r = min(r, ri)

print(r - l + 1 if r >= l else 0)
Problem p03738 (python)

Fixed submission:
A = int(input())
B = int(input())

if A > B:
    print('GREATER')
elif A < B:
    print('LESS')
else:
    print('EQUAL')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a > b:
    ans = 'GREATER'
elif a < b:
    ans = 'LESS'
else:
    ans = 'EQUAL
print(ans)
Problem p02700 (python)

Fixed submission:
a , b , c , d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

a_hp = a
b_hp = c

result = ""
while True :
	b_hp -= b
	if b_hp <= 0 :
		result ="Yes"
		break
		
	a_hp -= d
	if a_hp <= 0 :
		result = "No"
		break
print(result)

Buggy submission (verdict: Runtime Error):
a , b , c , d = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)

result = ""
while True :
	c -= b
	if c =< 0 :
		result ="Yse"
        break
		
	a -= d
	if a =< 0 :
		result = "No"
        break
print(result)
Problem p02664 (python)

Fixed submission:
a = input()

print(a.replace('P?', 'PD').replace('?D', 'PD').replace('??', 'PD').replace('?', 'D'))

Buggy submission (verdict: Runtime Error):

a=input()
ans = ''

for i,j in enumerate(a):
    if j == '?':
        if ans[-1] == 'P':
            ans+='D'
        elif a[i+1] == 'D':
            ans+='P'
        elif a[i+1] == '?':
            ans+='P'
        else:
            ans+='D'
    else:
        ans+=j

print(ans)

Buggy submission (verdict: Runtime Error):
a = input()
ans = []

for j in a:
    if j == '?':
        if ans[-1] == 'P':
            ans.append('D')
        else:
            ans.append('P')
    else:
        ans.append(j)

t = ''
for l in ans:
    t += l
print(t)
Problem p02683 (python)

Fixed submission:
from itertools import combinations
import numpy as np

n,m,x = map(int, input().split())
q = [np.array(list(map(int, input().split()))) for _ in range(n)]
L=[]
for i in range(1,n+1):
    for j in list(combinations(q,i)):
        S = np.sum(j, axis=0)
        if all([k >= x for k in S[1:]]):
            L.append(S[0])

if len(L) >0:
    print(min(L))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from itertools import combinations
import numpy as np

n,m,x = map(int, input().split())
q = [np.array(list(map(int, input().split()))) for _ in range(n)]
L=[]
for i in range(1,n):
    for j in list(combinations(q,i)):
        S = np.sum(j, axis=0)
        if all([k >= x for k in S[1:]]):
            L.append(S[0])

if len(L) >0:
    print(min(L))
else:
    print(-1)
Problem p02684 (python)

Fixed submission:
n,k = map(int, input().split())
a = list(map(lambda x : int(x) -1,  map(int, input().split())))

s = {0}
loop = [0]

while a[loop[-1]] not in s:
    loop.append(a[loop[-1]])
    s.add(loop[-1])

    
idx = loop.index(a[loop[-1]])

if k < len(loop):
    print(loop[k]+1)
else:
    print(loop[(k - idx)% (len(loop) - idx) + idx] + 1)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(lambda x : int(x) -1,  map(int, input().split())))

s = {0}
loop = [0]

while a[loop[-1]] not in s:
    loop.append(a[loop[-1]])
    s.add(loop[-1])

    
idx = loop.index(a[loop[-1]])

if k <= len(loop):
    print(loop[k]+1)
else:
    print(loop[(k - idx)% (len(loop) - idx) + idx] + 1)

Buggy submission (verdict: Runtime Error):
n,k = map(int, input().split())
a = list(map(lambda x : int(x) -1,  map(int, input().split()))

s = {0}
loop = [0]

while a[loop[-1]] not in s:
    loop.append(a[loop[-1]])
    s.add(loop[-1])

    
idx = loop.index(a[loop[-1]])

if k <= len(loop):
    print(loop[k-1]+1)
else:
    print(loop[(k - idx)% (len(loop) - idx) + idx] + 1)
Problem p02708 (python)

Fixed submission:
N,K = map(int, input().split())
ans = 0
for i in range(K,N+1):
    ans += (N*i - i**2 + i +1)%(10**9 +7)
print(ans%(10**9 +7) +1)

Buggy submission (verdict: Runtime Error):
N=int(input())
K=int(input())
ans = 0
for i in range(K,N+1):
    ans += (N*i - i**2 + i +1)%(10**9 +7)
print(ans%(10**9 +7))

Buggy submission (verdict: Runtime Error):
N=int(input())
K=int(input())
ans = 0
for i in range(K,N+1):
    ans += (N*i - i**2 + i +1)%(10**9 +7)
print(ans%(10**9 +7))
Problem p02714 (python)

Fixed submission:
N=int(input())
K=input()
dic = {}
ts = 'RGB'
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i, N):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)

Buggy submission (verdict: Runtime Error):
N=int(input())
K=input()
dic = {}
for t in ts:
    p=[]
    for ir, r in enumerate(K):
        if r == t:
            p.append(ir)
    dic[t] = p
ans1 = len(dic['R']) * len(dic['G']) * len(dic['B'])

ans2 = 0

for i in range(N):
    for j in range(i):
        if (i + 2*(j-i) < N):
            if  K[i] != K[j] and K[i] != K[i + 2*(j-i)] and K[i+2*(j-i)] != K[j]:
                ans2 +=1

print(ans1 - ans2)
Problem p02732 (python)

Fixed submission:
import collections
_ = int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M=0
for v in c.values():
    if v>1:
        M +=  v*(v-1)/2

for k in l:
    print(int(M-c[k]+1))

Buggy submission (verdict: Runtime Error):
import collections
_=int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M={}

for i,v in c.items():
    if v>1:
        M[i] =  v*(v-1)/2

for k in l:
    M_ = M.copy()
    M_[k] =  M_[k]*(c[k]-2)/c[k]
    print(int(sum(M_.values())))

Buggy submission (verdict: Runtime Error):
import collections
_=int(input())
l = list(map(int, input().split()))
c = collections.Counter(l)
M={}

for i,v in c.items():
    if v>1:
        M[i] =  v*(v-1)/2

for k in l:
    M_ = M.copy()
    M_[k] =  M_[k]*(c[k]-2)/c[k]
    print(sum(M_.values()))
Problem p02744 (python)

Fixed submission:
L=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i','j']
L_ind = [i for i in range(10)]
N=int(input())
K=[]
for i in range(N):
    if i==0:
        K.append(str(L_ind[0]))
    else:
        K_ = []
        for j in K:
            for m in range(int(max(set(j)))+2):
                K_.append(j + str(L_ind[m]))
        K = K_
    
for k in K:
    ans = ''
    for i in k:
        ans += L[int(i)]
    print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
 
if (c-a-b) **2 - 4*a*b > 0 and c-a-b > 0:
    print('Yes')
else:
    print('No')
Problem p02747 (python)

Fixed submission:
S=list(input())
while len(S)>1:
    if S[0] == 'h' and S[1] == 'i':
        S.remove('h')
        S.remove('i')
    else:   
        break

if len(S) == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):

S=list(input())
while len(S)>0:
    if S[0] == 'h' and S[1] == 'i':
        S.remove('h')
        S.remove('i')
    else:   
        break

if len(S) == 0:
    print('Yes')
else:
    print('No')
Problem p02756 (python)

Fixed submission:
from collections import deque

N = deque(input())
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if k%2 ==0:
            if q[1]=='1':
                N.appendleft(q[2])
            else:
                N.append(q[2])
        else:
            if q[1]=='2':
                N.appendleft(q[2])
            else:
                N.append(q[2])
if k%2==1:
    ans=''
    for x in reversed(N):
        ans += x
else:
    ans=''
    for x in N:
        ans += x

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

N = deque(input())
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if k%2 ==0:
            if q[1]=='1':
                N.appendleft(q[2])
            else:
                N.append(q[2])
        else:
            if q[1]=='2':
                N.appendleft(q[2])
            else:
                N.append(q[2])
if k%2==1:
    ans=''
    for x in N.rotate():
        ans += x
else:
    ans=''
    for x in N:
        ans += x
        
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
Q = int(input())
Qs = []
for _ in range(Q):
    Qs.append(list(map(str, input().split())) ) 
k=0
for q in Qs:
    if q[0] == '1':
        k+=1
    else:
        if (k%2 ==0　& q[1] == '1') or (k%2==1 & q[1] == '2'):
            N = q[2] + N
        else:
            N = N + q[2]

if k%2==1:
    ans = ''.join(list(reversed(N)))
    print(ans)
else:
    print(N)
Problem p02761 (python)

Fixed submission:
N,M = map(int, input().split())
L = []
ans = []
for i in range(M):
	L.append(list(map(int, input().split())))
	ans.append(False)

for i in range(10**N):
    num = str(i)
    if len(num) == N:
        for j,l in enumerate(L):
            if num[l[0]-1] == str(l[1]):
                ans[j] = True 
                continue
            else:
                break
        if all(ans):
            print(i)
            break
if not all(ans):
  print(-1)

Buggy submission (verdict: Runtime Error):
A = [[0 for i in range(10)]for l in range(N)]
ans = ''
end = False
for l in L:
    if l[0] == 1 & l[1] == 0:
        print(-1)
        end = True
        break
    else:
        A[l[0]-1][l[1]] = 1
if not end:
    if any(sum(a) > 1 for a in A):
        print(-1)
    else:
        for i in range(N):
            if i == 0:
                if sum(A[i]) == 0:
                    ans+='1'
                else:
                    ans+=str(A[i].index(1))
            else:
                if sum(A[i]) == 0:
                    ans+='0'
                else:
                    ans+=str(A[i].index(1))

        print(ans)
Problem p02772 (python)

Fixed submission:
import numpy as np


N = int(input())
AN = list(map(int, input().split()))
AN = np.array(AN)

AN2 = AN[AN % 2 == 0]

if AN2[AN2 % 3 == 0].size + AN2[AN2 % 5 ==0].size - AN2[AN2 % 15 ==0].size == AN2.size :
    print('APPROVED')

else:
    print('DENIED')

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

AN2 = AN[AN % 2 == 0]
(AN % 2 == 0).size
if AN2[AN2 % 3 == 0].size + AN2[AN2 % 5 ==0].size - AN2[AN2 % 15 ==0].size == AN2.size:
    print('APPROVED')

else:
    print('DENIED')

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

AN2 = AN[AN % 2 == 0]
(AN % 2 == 0).size
if AN2[AN2 % 3 == 0].size + AN2[AN2 % 5 ==0].size - AN2[AN2 % 15 ==0].size == AN2.size :
    print('APPROVED')

else:
    print('DENIED')
Problem p02778 (python)

Fixed submission:
s = str(input())
for i in range(len(s)):
    s = s.replace(s[i], 'x')
  
print(s)

Buggy submission (verdict: Runtime Error):
s = str(input())
for i in range(len(s)):
  s[i] = 'x'
  
print(s)
Problem p02658 (python)

Fixed submission:
def main ():
  N = int(input())
  A = list(map(int,input(). split ()))
  if 0 in A:
      print(0)
      return

  prod = 1
  for a in A:
      prod *= a
      if prod > 1000000000000000000:
          print(-1)
          return
  print(prod)

main ()

Buggy submission (verdict: Runtime Error):
#TIME : 
import sys
from math import sqrt
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

MAX = 10**18
n = inp()
a = inlt()
if 0 in A:
    print(0)
    exit()
res = 1
for num in a:
    res*=num
if res > MAX:
    print(-1)
else:
    print(res)
Problem p02719 (python)

Fixed submission:
str = input().split()
n = int(str[0])
k = int(str[1])
t = n%k
other = abs(k-t)
print(min(t,other))

Buggy submission (verdict: Runtime Error):
str = input().split()
a1 = int(str[0])
a2 = int(str[1])
diff = abs(a1-a2)
if diff > a2 :
    larger = diff
    smaller = a2
else:
    larger = a2
    smaller = diff
print(larger%smaller)

Buggy submission (verdict: Runtime Error):
str = input().split()
a1 = int(str[0])
a2 = int(str[1])
diff = abs(a1-a2)
if diff > a2 :
    larger = diff
    smaller = a2
else:
    larger = a2
    smaller = diff
print(larger%smaller)
Problem p02720 (python)

Fixed submission:
from collections import deque

k = int(input())
lunlun = []
q = deque([1,2,3,4,5,6,7,8,9])
while len(lunlun) <= k:
    first = q.popleft()
    lunlun.append(first)
    if first%10-1 >= 0:
        q.append(first*10 + (first%10-1))
    q.append(first*10 + first%10)
    if first%10+1 <= 9:
        q.append(10*first + (first%10+1))
print(lunlun[k-1])

Buggy submission (verdict: Runtime Error):
from collections import deque

k = int(input())
lunlun = []
q = deque([1,2,3,4,5,6,7,8,9])
for i in range(k-1):
    first = q.popleft()
    if first%10-1 >= 0:
        q.append(first*10 + (first%10-1))
    q.append(first*10 + first%10)
    if first%10+1 <= 9:
        q.append(10*first + (first%10+1))
    print(q)
print(q[0])
Problem p02658 (python)

Fixed submission:
n = int(input())
aa = list(map(int, input().split()))
if 0 in aa:
  print(0)
else:
  ans = 1
  for a in aa:
    ans = ans * a
    if ans > 10**18:
      break
  print(-1 if ans > 10**18 else ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
aa = list(map(int, input().split()))
if 0 in aa:
  print(0)
else:
  ans = 1
  for a in aa:
    ans = ans * a
    if ans > 10**18:
      break
print(-1 if ans > 10**18 else ans)