Problem p02720 (python)

Fixed submission:
k = int(input())
lunlun = []
def dfs(A):
    if len(A) == 10:
        return
    else:
        start = int(A[-1])
        if start == 9:
            for i in range(start-1, start+1):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        elif start == 0:
            for i in range(start, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
        else:
            for i in range(start-1, start+2):
                A.append(str(i))
                lunlun.append("".join(A))
                dfs(A)
                A.pop()
for j in range(1, 10):
    lunlun.append(str(j))
    dfs([str(j)])
lunlun = list(map(int, lunlun))
lunlun.sort()
print(lunlun[k-1])

Buggy submission (verdict: Runtime Error):
k = int(input())
table = [1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98]
key1, key2,key3 = 0,0,0
for i in range(1,9):
    key1=int(str(i)+str(i-1)+str(i-1))
    key2=int(str(i)+str(i)+str(i))
    key3=int(str(i)+str(i+1)+str(i+1))
    table.append(key1-1)
    table.append(key1)
    table.append(key1+1)
    table.append(key2-1)
    table.append(key2)
    table.append(key2+1)
    table.append(key3-1)
    table.append(key3)
    table.append(key3+1)
table.pop()
table.append(987)
table.append(988)
table.append(989)
table.append(998)
table.append(999)
table.append(1000)
table.append(1001)
table.append(1010)
table.append(1011)
table.append(1012)
table.append(1100)
table.append(1101)
table.append(1110)
table.append(1111)
table.append(1112)
table.append(1121)
table.append(1122)
table.append(1123)
table.append(1210)
table.append(1211)
table.append(1212)
table.append(1221)
table.append(1222)
table.append(1223)
table.append(1232)
table.append(1233)
table.append(1234)
for j in range(2,9):
        key1=int(str(j)+str(j-1)+str(j-1)+str(j-1))
        key2=int(str(j)+str(j)+str(j)+str(j))
        key3=int(str(j)+str(j+1)+str(j+1)+str(j+1))    
    table.append(key1-1)
    table.append(key1)
    table.append(key1+1)
    table.append(key2-1)
    table.append(key2)
    table.append(key2+1)
    table.append(key3-1)
    table.append(key3)
    table.append(key3+1)
table.pop()
table.append(9887)
table.append(9888)
table.append(9889)
table.append(9998)
table.append(9999)
print(table[k-1])

Buggy submission (verdict: Runtime Error):
k = int(input())
table = [1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98]
for i in range(1,9):
    key1=int(str(i)+str(i-1)+str(i-1))
    key2=int(str(i)+str(i)+str(i))
    key3=int(str(i)+str(i+1)+str(i+1))
    table.append(key1-1)
    table.append(key1)
    table.append(key1+1)
    table.append(key2-1)
    table.append(key2)
    table.append(key2+1)
    table.append(key3-1)
    table.append(key3)
    table.append(key3+1)
table.pop()
table.append(987)
table.append(988)
table.append(989)
table.append(998)
table.append(999)
table.append(1000)
table.append(1001)
table.append(1010)
table.append(1011)
table.append(1012)
table.append(1100)
table.append(1101)
table.append(1110)
table.append(1111)
table.append(1112)
table.append(1121)
table.append(1122)
table.append(1123)
table.append(1210)
table.append(1211)
table.append(1212)
table.append(1221)
table.append(1222)
table.append(1223)
table.append(1232)
table.append(1233)
table.append(1234)
for j in range(2,9):
        key1=int(str(j)+str(j-1)+str(j-1)+str(j-1))
        key2=int(str(j)+str(j)+str(j)+str(j))
        key3=int(str(j)+str(j+1)+str(j+1)+str(j+1))    
    table.append(key1-1)
    table.append(key1)
    table.append(key1+1)
    table.append(key2-1)
    table.append(key2)
    table.append(key2+1)
    table.append(key3-1)
    table.append(key3)
    table.append(key3+1)
table.pop()
table.append(9887)
table.append(9888)
table.append(9889)
table.append(9998)
table.append(9999)
print(table[k-1])