alexjercan/bugnet huggingface dataset:
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3

a, b, c = map(int, input().split())
print("{} {} {}".format(c, a, b))


Error: ValueError: invalid literal for int() with base 10: '1 2 3'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s892793306.py", line 3, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '1 2 3'


Fixed submission:

#!/usr/bin/env python3

a = int(input())
a, b = map(int, input().split())
a = list(str(input()))
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

x, y, z = map(int, input().split())
print(z, x, y)


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s498360594.py", line 1, in <module>
    x, y, z = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

x, y, z = map(int, input())
print(z, x, y)
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

X, Y, Z = map(int, input().split())
print(Z, X, Y)


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s623686087.py", line 1, in <module>
    X, Y, Z = map(int, input())
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

X, Y, Z = map(int, input())
print(Z, X, Y)
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

x, y, z = map(str, input().split())
print(z + " " + x + " " + y)


Error: TypeError: unsupported operand type(s) for +: 'int' and 'str'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s693185745.py", line 2, in <module>
    print(z + " " + x + " " + y)
TypeError: unsupported operand type(s) for +: 'int' and 'str'


Fixed submission:

x, y, z = map(int, input().split())
print(z + " " + x + " " + y)
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

def resolve():
    a, b, c = map(int, input().split())

    temp_a = a
    temp_b = b
    a = temp_b
    b = temp_a
    temp_c = c
    temp_a = a
    c = temp_a
    a = temp_c
    print(a, b, c)


resolve()


Error: ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s151641431.py", line 8, in <module>
    resolve()
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s151641431.py", line 3, in resolve
    a, b, c = map(int, list(input()))
ValueError: invalid literal for int() with base 10: ' '


Fixed submission:

# -*- coding: utf-8 -*-
def resolve():
    a, b, c = map(int, list(input()))
    print(a + b + c)


if __name__ == "__main__":
    resolve()
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

XYZ = input().split()
print(XYZ[2], XYZ[0], XYZ[1])


Error: TypeError: 'map' object is not subscriptable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s285964975.py", line 2, in <module>
    print(XYZ[2], XYZ[1], XYZ[0])
TypeError: 'map' object is not subscriptable


Fixed submission:

XYZ = map(int, input().split())
print(XYZ[2], XYZ[1], XYZ[0])
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

a, b, c = map(int, input().split())
print(c, a, b)


Error: ValueError: invalid literal for int() with base 10: '1 2 3'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s384192178.py", line 1, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '1 2 3'


Fixed submission:

a = int(input())
b = int(input())
c = int(input())
print(c, a, b)
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

data = input().split()
i = [int(n) for n in data]
res = "{} {} {}"
print(res.format(i[2], i[0], i[1]))


Error: 0

Fixed submission:

data = input().split()

i = [int(n) for n in data]

print(f"{i[2]} {i[0]} {i[1]}")
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

x, y, z = input().split()
print(z, x, y)


Error: 0

Fixed submission:

x, y, z = input().split()
print(f"{z} {x} {y}")
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

X, Y, Z = input().split()
A = X
B = Y
C = Z
# swap the contents of the boxes A and B
temp = B
B = A
A = temp
# swap the contents of the boxes A and C
swapAC = C
C = A
A = swapAC
print(A, B, C)


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02717/Python/s970724888.py", line 2, in <module>
    Y = input()
EOFError: EOF when reading a line


Fixed submission:

X = input()
Y = input()
Z = input()
A = X
B = Y
C = Z
# swap the contents of the boxes A and B
temp = B
B = A
A = temp
print(A + " " + B + " " + C)
# swap the contents of the boxes A and C
swapAC = C
C = A
A = swapAC
print(A + " " + B + " " + C)
Problem p02717 (Python) — buggy submission, verdict: Runtime Error

X, Y, Z = map(int, input().split())
print(Z, X, Y)


Error: 0

Fixed submission:

X, Y, Z = map(int, input().split())
print(f"{Z} {X} {Y}")
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort(reverse=True)
real = A[M - 1] / sum(A)
ideal = 1 / (4 * M)

if real >= ideal:
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

real = A[M] / sum(A)
ideal = 1 / (4 * M)

if real >= ideal:
    print("Yes")
else:
    print("No")
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

n, m = set(map(int, input().split()))
a = set(map(int, input().split()))
count = 0
for x in a:
    if x >= sum(a) / (4 * m):
        count += 1
if m <= count:
    print("Yes")
else:
    print("No")
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())

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

s = sum(a)

a.sort(reverse=True)

if a[m - 1] >= s / (4 * m):
    print("Yes")
else:
    print("No")


Error: TypeError: '>=' not supported between instances of 'list' and 'int'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02718/Python/s183139755.py", line 9, in <module>
    if a[m - 1] * a * m >= s:
TypeError: '>=' not supported between instances of 'list' and 'int'


Fixed submission:

n, m = map(int, input().split())

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

s = sum(a)

a.sort()

if a[m - 1] * a * m >= s:
    print("Yes")
else:
    print("No")
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

# -*- coding: utf-8 -*-

N, M = map(int, input().split())
A = list(map(int, input().split()))

th = 1.0 * sum(A) / (4 * M)

sorted_A = sorted(A, key=lambda x: -x)
if sorted_A[M - 1] < th:
    print("No")
else:
    print("Yes")


Error: 0

Fixed submission:

# -*- coding: utf-8 -*-

N, M = map(int, input().split())
A = list(map(int, input().split()))

th = sum(A) // (4 * M)

sorted_A = sorted(A, key=lambda x: -x)
if sorted_A[M] < th:
    print("No")
else:
    print("Yes")
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

#!/usr/bin/env python3

import numpy as np

N, M = map(int, input().split())
A = list(map(int, input().split()))

A = np.array(A)

num = np.sum(A >= np.sum(A) / (4 * M))

if num >= M:
    print("Yes")
else:
    print("No")


Error: ValueError: invalid literal for int() with base 10: '4 1'
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02718/Python/s781697127.py", line 3, in <module>
    a = int(input())
ValueError: invalid literal for int() with base 10: '4 1'


Fixed submission:

#!/usr/bin/env python3

a = int(input())
a, b = map(int, input().split())
a = list(str(input()))
Problem p02718 (Python) — buggy submission, verdict: Runtime Error

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if a[m - 1] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")


Error: 0

Fixed submission:

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if a[m] >= sum(a) / (4 * m):
    print("Yes")
else:
    print("No")
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()

i = N // K
N = N - K * i
while True:
    i = N // K
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)


Error: TLE

Fixed submission:

N, K = map(int, input().split())

flag = 0
if K == 1:
    print(0)
    quit()
if K == 2:
    if N % 2:
        print(1)
        quit()
    else:
        print(0)
        quit()
while True:
    ab = abs(N - K)
    if N > ab:
        N = ab
    else:
        break

print(N)
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())
if n == 0 or n == k:
    print(0)
else:
    a = abs(n % k)
    b = abs(a - k)
    print(min(a, b))


Error: 0

Fixed submission:

n, k = map(int, input().split())
if n == 0:
    print(0)
else:
    x = abs(n - k)
    a = n % x
    b = abs(a - k)
    print(min(a, b))
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())

N %= K

while abs(N - K) < N:
    N = abs(N - K)

print(N)


Error: TLE

Fixed submission:

N, K = map(int, input().split())

while abs(N - K) < N:
    N = abs(N - K)

print(N)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())

cm = N
k = N % K
if k == 0:
    print(0)
    exit()
print(min(abs(k - K), N))


Error: TLE

Fixed submission:

N, K = map(int, input().split())

cm = N
if N % K == 0:
    print(0)
    exit()
while True:
    cm = min(cm, abs(N - K))
    if cm >= N:
        break
    N = cm

print(cm)
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().split())

print(min((n % k), (k - (n % k))))


Error: TypeError: 'int' object is not iterable
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02719/Python/s891781735.py", line 3, in <module>
    print(min(n % k), (k - (n % k)))
TypeError: 'int' object is not iterable


Fixed submission:

n, k = map(int, input().split())

print(min(n % k), (k - (n % k)))
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

n, m = (int(x) for x in input().split())

a = n % m
b = n / m
if abs(a - m) > a:
    print(a)
else:
    print(abs(a - m))


Error: EOFError: EOF when reading a line
Traceback (most recent call last):
  File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02719/Python/s837857825.py", line 2, in <module>
    num_point = [int(x) for x in input().split()]
EOFError: EOF when reading a line


Fixed submission:

n, m = (int(x) for x in input().split())
num_point = [int(x) for x in input().split()]
count = 0

for n in num_point:
    if n > (sum(num_point) / (4 * m)):
        count += 1

if count < m:
    print("No")
else:
    print("Yes")
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

list_input = [int(n) for n in input().split()]

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    if N >= K:
        N = N % K
    else:
        N = K - N
print(N)


Error: TLE

Fixed submission:

list_input = [int(n) for n in input().split()]

N = list_input[0]
K = list_input[1]

while N > abs(N - K):
    N = abs(N - K)

print(N)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

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

print(min(n % k, abs(k - n % k)))


Error: TLE

Fixed submission:

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

n_prev = n

while True:
    n = abs(n - k)
    if n > n_prev:
        print(n_prev)
        exit()
    else:
        n_prev = n
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

N, K = map(int, input().split())
print(min(N % K, K - (N % K)))


Error: TLE

Fixed submission:

N, K = map(int, input().split())

tmp1 = abs(N - K)

while True:
    if K == 1:
        print(0)
        break
    tmp2 = abs(tmp1 - K)
    if tmp1 < tmp2:
        print(tmp1)
        break
    else:
        tmp1 = tmp2
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())

x = n % k
y = abs(x - k)

if x < y:
    print(x)
else:
    print(y)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
min = n
fin = 0

while n >= 0:
    n = n - k
    if n >= 0:
        min = n
    else:
        fin = abs(n)

if min < fin:
    print(min)
else:
    print(fin)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())

r = []
n = n % k
if n == 0:
    print(0)
    exit()
while True:
    n = abs(n - k)
    r.append(n)
    if r.count(n) >= 2:
        break

print(min(r))


Error: TLE

Fixed submission:

n, k = map(int, input().split())

r = []
if n % k == 0:
    print(0)
    exit()
while True:
    n = abs(n - k)
    r.append(n)
    if r.count(n) >= 2:
        break

print(min(r))
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

N, K = map(int, input().split())
ans = int(N)
N_1 = N
N_2 = N
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
    if ans > abs(N):
        ans = abs(N)
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)


Error: WA

Fixed submission:

N, K = map(int, input().split())
ans = int(N)
k_range = N // K
# print(k_range)

if k_range == 0:
    N = N - K
else:
    N_1 = N - (K * k_range)
    N_2 = N - (K * (k_range + 1))
    print(N_1)
    print(N_2)

if abs(N_1) < abs(N_2):
    if ans > abs(N_1):
        ans = abs(N_1)
    else:
        pass
else:
    if ans > abs(N_2):
        ans = abs(N_2)
    else:
        pass
print(ans)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
if n % k == 0:
    print(0)
else:
    l = [n]
    p = n // k
    c = n - (p * k)
    half = k // 2
    while c > half:
        c = abs(c - k)
    l.append(c)
    print(min(l))


Error: TLE

Fixed submission:

N, K = map(int, input().split())
Nj = N
while True:
    Ni = Nj
    Nj = abs(Ni - K)
    if Ni > N:
        print(N)
        break
    elif Nj > Ni:
        print(Ni)
        break
    elif K == 1 or Nj == K:
        print(0)
        break
    else:
        continue
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

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

print(min(N % K, K - (N % K)))


Error: WA

Fixed submission:

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

if N >= K:
    print(N % K)
else:
    print(K % N)
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

n, k = map(int, input().strip().split())

min_n = 1000000000000000000000000000
for i in range(1000):
    if n > k:
        n %= k
    n = abs(n - k)
    min_n = min(min_n, n)

print(min_n)


Error: 0

Fixed submission:

n, k = map(int, input().strip().split())

prev = None

n = n % k
print(min(n, k % n))
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = list(map(int, input().split()))
if n == k:
    n = 0
else:
    while n > abs(n - k):
        if n > k:
            n = min(n, n % k)
        elif k > n:
            n = min(n, k % n)

print(n)


Error: TLE

Fixed submission:

n, k = list(map(int, input().split()))
loop = True
while loop:
    if n > abs(n - k):
        if n > k:
            n = min(n, n % k)
        elif k > n:
            n = min(n, k % n)
    else:
        loop = False

print(n)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
if n == 0 or k == 1:
    print(0)
    exit()
elif n < k:
    print(min(n, abs(n - k)))
    exit()
elif n % k == 0:
    print(0)
    exit()
else:
    mx = n % k
print(min(abs(mx - k), mx))


Error: TLE

Fixed submission:

N, K = map(int, input().split())
if N % K == 0:
    print(0)
else:
    li = []
    li.append(N)
    aoki = N
    while aoki <= min(li):
        aoki = abs(min(li) - K)
        li.append(aoki)
    print(min(li))
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

#!python3

# input
N, K = list(map(int, input().split()))


def main():
    s = N % K
    ans = min(s, K - s)
    print(ans)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

#!python3

# input
N, K = list(map(int, input().split()))


def main():
    x = N
    while True:
        y = max(x - K, K - x)
        if y < x:
            x = y
        else:
            break
    print(x)


if __name__ == "__main__":
    main()
Problem p02719 (Python) — buggy submission, verdict: Runtime Error

import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
if N == K:
    print(0)
elif N > K:
    N %= K
    print(min(N, abs(N - K)))
else:
    print(min(N, abs(N - K)))


Error: 0

Fixed submission:

import sys

read = sys.stdin.read
readline = sys.stdin.readline

N, K = map(int, read().split())
d = abs(N - K)
N %= d
if abs(N - K) < N:
    print(abs(N - K))
else:
    print(N)
Problem p02719 (Python) — buggy submission, verdict: Time Limit Exceeded

n, k = map(int, input().split())
# n, k = map(int, "2 6".split())
q = n // k  # 答え
mod = n % k  # あまり

if q == 0:

    while True:
        nc = n
        n = n - k
        if n <= 0:
            if abs(n) < nc:
                print(abs(n))
                break
            else:
                print(nc)
                break
else:
    n1 = abs(n - (q * k))
    n2 = abs(n - ((q + 1) * k))
    if n1 < n2:
        print(n1)
    else:
        print(n2)


Error: TLE

Fixed submission:

n, k = map(int, input().split())
# n, k = map(int, "2 6".split())

while True:
    nc = n
    n = n - k
    if n <= 0:
        if abs(n) < nc:
            print(abs(n))
            break
        else:
            print(nc)
            break
Problem p02720 (Python) — buggy submission, verdict: Runtime Error

import numpy as np

K = int(input())

top = np.ones(10, dtype=int)
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = np.dot(tmp, adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break


print("".join(list(map(str, ans))[::-1]))


Error: TLE

Fixed submission:

import numpy as np

K = int(input())

top = np.ones(10, dtype=int)
# top[0] = 0
adj = np.eye(10, dtype=int)
adj[1:, :-1] += np.eye(9, dtype=int)
adj[:-1, 1:] += np.eye(9, dtype=int)

counts = [top]
tmp = top
for _ in range(10):
    tmp = tmp.__matmul__(adj)
    counts.append(tmp)

for i in range(10):
    for j in range(1, 10):
        if K > counts[i][j]:
            K -= counts[i][j]
        else:
            break
    else:
        continue
    break

ans = [-1] * (i + 1)
ans[i] = j

for d in range(i, 0, -1):
    for k in range(max(0, j - 1), min(9, j + 1) + 1):
        if K > counts[d - 1][k]:
            K -= counts[d - 1][k]
        else:
            ans[d - 1] = k
            j = k
            break


print("".join(list(map(str, ans))[::-1]))
Problem p02720 (Python) — buggy submission, verdict: Time Limit Exceeded

from collections import deque

k = int(input())

q = deque(range(1, 10))

for i in range(k):
    t = q.popleft()

    if t % 10 != 0:
        q.append(10 * t + t % 10 - 1)

    q.append(10 * t + t % 10)

    if t % 10 != 9:
        q.append(10 * t + t % 10 + 1)

print(t)


Error: TLE

Fixed submission:

import math

k = int(input())

a = []

s = str(k)
flg = 0

for i in range(1, 1000000):
    n = math.floor(math.log10(i))
    s = str(i)
    cnt = 0

    if n < 1:
        a.append(i)
    else:
        for j in range(n):
            if abs(int(s[j]) - int(s[j + 1])) <= 1:
                cnt += 1
            if cnt == n:
                a.append(i)

    if len(a) == k:
        print(a[k - 1])
        break
Problem p02720 (Python) — buggy submission, verdict: Runtime Error

import math

k = int(input())

l = [1, 2, 3, 4, 5, 6, 7, 8, 9]

c = 0
while k > len(l):
    f = l[c] - (l[c] // 10 * 10)

    if f != 0:
        l.append(l[c] * 10 + f - 1)

    l.append(l[c] * 10 + f)

    if f != 9:
        l.append(l[c] * 10 + f + 1)

    c += 1

print(l[k - 1])


Error: 0

Fixed submission:

n = int(input())

arr = []
for i in range(10000):
    si = str(i + 1)
    for i2 in range(len(si) - 1):
        if abs(int(si[i2]) - int(si[i2 + 1])) >= 2:
            break
    else:
        arr.append(si)

print(arr[n - 1])
Problem p02720 (Python) — buggy submission, verdict: Time Limit Exceeded

def main():
    k = int(input())
    lunluns = [i for i in range(1, 10)]
    if k <= len(lunluns):
        print(lunluns[k - 1])
        return

    while True:
        if k <= len(lunluns):
            print(lunluns[k - 1])
            return
        k -= len(lunluns)
        olds = lunluns
        lunluns = []
        for old in olds:
            for i in (-1, 0, 1):
                digit_next = old % 10 + i
                if digit_next < 0 or digit_next > 9:
                    continue
                new = old * 10 + digit_next
                lunluns.append(new)


if __name__ == "__main__":
    main()


Error: TLE

Fixed submission:

k = int(input())
border = 10000
if k < border:
    candidate = 1
    count = 1
    while True:
        if count == k:
            print(candidate)
            break

        candidate += 1
        digits = tuple(int(c) for c in str(candidate))
        for i, d in enumerate(digits[:-1]):
            if abs(d - digits[i + 1]) > 1:
                break
        else:
            count += 1

else:
    candidate = 3234566667
    count = 100000
    while True:
        if count == k:
            print(candidate)
            break

        digits = tuple(int(c) for c in str(candidate))
        for i, d in enumerate(digits[:-1]):
            if abs(d - digits[i + 1]) > 1:
                break
        else:
            count -= 1

        candidate -= 1

# Candidate 100000 -> 3234566667
Problem p02720 (Python) — buggy submission, verdict: Time Limit Exceeded

from sys import stdin
from collections import deque

K = int(stdin.readline())

deque = deque()
for i in range(1, 10):
    deque.append(i)

for i in range(K - 1):
    s = deque.popleft()
    for j in range(-1, 2):
        add = (s % 10) + j
        if 0 <= add <= 9:
            deque.append(s * 10 + add)

print(deque.popleft())


Error: TLE

Fixed submission:

from sys import stdin

K = int(stdin.readline())

if K < 50000:
    count = 0
    for _ in range(1, 3234566667):
        i = str(_)
        L = len(i)
        for j in range(1, L):
            if abs(ord(i[j]) - ord(i[j - 1])) > 1:
                break
        else:
            count += 1
            if count == K:
                print(_)
                quit()
else:
    count = 100001
    for _ in range(1, 3234566668)[::-1]:
        i = str(_)
        L = len(i)
        for j in range(1, L):
            if abs(ord(i[j]) - ord(i[j - 1])) > 1:
                break
        else:
            count -= 1
            if count == K:
                print(_)
                quit()