Problem:


Score : 400 points

Problem Statement

A positive integer X is said to be a lunlun number if and only if the following condition is satisfied:

In the base ten representation of X (without leading zeros), for every pair of two adjacent digits, the absolute difference of those digits is at most 1.

For example, 1234, 1, and 334 are lunlun numbers, while none of 31415, 119, or 13579 is.

You are given a positive integer K. Find the K-th smallest lunlun number.

Constraints

1 \leq K \leq 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

K

Output

Print the answer.

Sample Input 1

15

Sample Output 1

23

We will list the 15 smallest lunlun numbers in ascending order:

1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
21,
22,
23.

Thus, the answer is 23.

Sample Input 2

1

Sample Output 2

1

Sample Input 3

13

Sample Output 3

21

Sample Input 4

100000

Sample Output 4

3234566667

Note that the answer may not fit into the 32-bit signed integer type.



Sample input:
15


Sample output:
23

Submission status: Wrong Answer

Solution code:
K = int(input())

def lunlun(n):
    x = str(n)
    if len(x)==1:
        return True
    else:
        for i in range(len(x)-1):
            if abs(int(x[i])-int(x[i+1]))>1:
                return False
        else:
            return True

i = 0
j = 0
while i<K:
  if lunlun(j):
    i +=1
  j += 1

print(j)

Submission status: Wrong Answer

Solution code:
from collections import deque
k=int(input())

q=deque([1,2,3,4,5,6,7,8,9])
count=0

while count<k:  
  j=q.popleft()
  count+=1
  if count==k:
    print(j)
    break
  if j%10!=10:
    q.append(j*10+j%10-1)
  q.append(j*10+j%10)
  if j%10!=9:
    q.append(j*10+j%10+1)

Submission status: Wrong Answer

Solution code:
def resolve():
    from collections import deque
    k = int(input())
    a = [1,2,3,4,5,6,7,8,9]
    a = deque(a)
    c = 0
    if k < 10:
        print(k)
    else:
        while c != k:
            c += 1
            t = a.popleft()
            if t % 10 == 0:
                a.append(t*10)
                a.append(t*10+1)
            elif t % 10 == 9:
                a.append(t * 10 + 9)
                a.append(t * 10 + 8)
            else:
                a.append(t * 10 + (t%10)-1)
                a.append(t * 10 + (t%10))
                a.append(t * 10 + (t%10)+1)
        print(t)
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    from collections import deque
    k = int(input())
    a = [1,2,3,4,5,6,7,8,9]
    a = deque(a)
    c = 0
    if k < 10:
        print(k)

    else:
        while c != k:
            c += 1
            t = a.popleft()
            if t % 10 == 0:
                a.append(t*10)
                a.append(t*10+1)
            elif t % 10 == 9:
                a.append(t * 10 + 9)
                a.append(t * 10 + 8)
            else:
                a.append(t * 10 + (t%10)-1)
                a.append(t * 10 + (t%10))
                a.append(t * 10 + (t%10)+1)
            if c == k:
                print(t)


resolve()

Submission status: Wrong Answer

Solution code:
k = int(input())
que = []
for i in range(1,10):
  que.append(i)
ct = 0
while(len(que) < k):
  ct += 1
  x = que[0]
  que.remove(x)
  if (x%10 != 0):
    que.append((10*x) + (x%10) - 1)
    que.append((10*x) + (x%10))
  if (x%10 != 9):
    que.append((10*x) + (x%10) + 1)
print(que[k-1-ct])

Submission status: Wrong Answer

Solution code:
K=int(input())

accept=1
for i in range(1,10**5):
    l=list(str(i))
    if accept <= K:
        accept += 1
        if len(l)>1:
            for j in range(len(l)-1):
                if abs(int(l[j])-int(l[j+1]))>1:
                    accept -= 1
                    break
    else:
        print(i-1)
        break

Submission status: Wrong Answer

Solution code:
K = int(input())
def L(x):
    X = int(x)
    if X < 10:
        return True
    elif X <100:
        if abs(int(x[-2]) -int(x[-1])) <= 1:
            return True
        else:
            return False
    elif X <(10 ** 3):
        if abs(int(x[-3]) - int(x[-2])) <= 1 and abs(int(x[-2]) -int(x[-1])) <= 1:
            return True
        else:
            return False
    elif X <(10 ** 4):
        if abs(int(x[-4]) - int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-1]))<= 1:
            return True
        else:
            return False
    elif X <=(10 ** 5):
        if abs(int(x[-5]) - int(x[-4])) <= 1 and abs(int(x[-4]) - int(x[-3])) == 1 and abs(int(x[-2]) -int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-1]))<= 1:
            return True
        else:
            return False
I = 1
i = 1
while I != (K+1):
    print([i,I])
    if L(str(i)):
         I += 1
         i += 1
    else:
        i += 1
print(i-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
def L(x):
    X = int(x)
    if X < 10:
        return True
    elif X <100:
        if abs((int(x) // 10) - int(x) % 10) <= 1:
            return True
        else:
            return False
    elif X <(10 ** 3):
        if abs(int(x[-3]) - int(x[-2])) <= 1 and abs(int(x[-2]) -int(x[-1])) <= 1:
            return True
        else:
            return False
    elif X <(10 ** 4):
        if abs(int(x[-4]) - int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-1]))<= 1:
            return True
        else:
            return False
    elif X <=(10 ** 5):
        if abs(int(x[-5]) - int(x[-4])) <= 1 and abs(int(x[-4]) - int(x[-3])) == 1 and abs(int(x[-2]) -int(x[-3])) <= 1 and abs(int(x[-2]) -int(x[-1]))<= 1:
            return True
        else:
            return False
I = 1
i = 1
while I != (K+1):
    if L(str(i)):
         I += 1
         i += 1
    else:
        i += 1
print(i-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(str, (range(1, 10))))
total = a[:]
cnt = 9
if n <= 9:
    print(n)
else:
    while cnt < n:
        new = []
        for i in a:
            if i[-1] == "0":
                new.append(i + "0")
                new.append(i + "1")
                cnt += 2
                if cnt >= n:
                    break
            elif i[-1] == "9":
                new.append(i + "8")
                new.append(i + "9")
                cnt += 2
                if cnt >= n:
                    break
            else:
                new.append(i + str(int(i[-1]) -1))
                new.append(i + str(int(i[-1])))
                new.append(i + str(int(i[-1]) + 1))
                cnt += 3
                if cnt >= n:
                    break
        total += new[:]
        a = new[:]
                
print(total[n-1])

Submission status: Wrong Answer

Solution code:
import queue
K=int(input())
x=queue.Queue()
for j in range(0,9):
    x.put(j)
for i in range(K+1):
    y=x.get()
    if y%10!=0:
        x.put(10*y+y%10-1)
    x.put(10*y+y%10)
    if y%10!=9:
        x.put(10*y+y%10+1)
print(x.get())

Submission status: Wrong Answer

Solution code:
#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)
            top_keta = lower_keta // 10**(ketasu-1)

            if top_keta !=1: 
                #print((top_keta-1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta-1)*10**ketasu + lower_keta)

            #print((top_keta+0)*10**ketasu + lower_keta)
            new_lunlun_numbers_list.append((top_keta+0)*10**ketasu + lower_keta)

            if top_keta !=9:
                #print((top_keta+1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta+1)*10**ketasu + lower_keta)

        #10……0,を入れる
        ketasu = int(math.log10(new_lunlun_numbers_list[-1])//1 + 1)
        new_lunlun_numbers_list.append((1)*10**(ketasu-1))
        #10...1を入れる
        if ketasu !=2: #11の重複防止
            new_lunlun_numbers_list.append((1)*10**(ketasu-1)+1)


        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            #print(new_lunlun_numbers_list)
            break
        else:
            lunlun_numbers_numer+=len(new_lunlun_numbers_list)

        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list)

Submission status: Wrong Answer

Solution code:
#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)
            top_keta = lower_keta // 10**(ketasu-1)

            if top_keta !=1: 
                #print((top_keta-1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta-1)*10**ketasu + lower_keta)

            #print((top_keta+0)*10**ketasu + lower_keta)
            new_lunlun_numbers_list.append((top_keta+0)*10**ketasu + lower_keta)

            if top_keta !=9:
                #print((top_keta+1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta+1)*10**ketasu + lower_keta)

        #10……0,を入れる
        ketasu = int(math.log10(new_lunlun_numbers_list[-1])//1 + 1)
        new_lunlun_numbers_list.append((1)*10**(ketasu-1))
        #10...1を入れる
        if ketasu !=2: #11の重複防止
            new_lunlun_numbers_list.append((1)*10**(ketasu-1)+1)


        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            #print(new_lunlun_numbers_list)
            break


        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list)

Submission status: Wrong Answer

Solution code:
#161d
import math
import copy

K = int(input())

keta = 1
lunlun_numbers_list = [1,2,3,4,5,6,7,8,9]
lunlun_numbers_numer = 9

if K <=9:
    print(lunlun_numbers_list[K-1])
else:
    while 1:
        new_lunlun_numbers_list = list()
        for lower_keta in lunlun_numbers_list:
            ketasu = int(math.log10(lower_keta)//1 + 1)
            top_keta = lower_keta // 10**(ketasu-1)

            if top_keta !=1: 
                #print((top_keta-1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta-1)*10**ketasu + lower_keta)

            #print((top_keta+0)*10**ketasu + lower_keta)
            new_lunlun_numbers_list.append((top_keta+0)*10**ketasu + lower_keta)

            if top_keta !=9:
                #print((top_keta+1)*10**ketasu + lower_keta)
                new_lunlun_numbers_list.append((top_keta+1)*10**ketasu + lower_keta)

        #10……0,を入れる
        ketasu = int(math.log10(new_lunlun_numbers_list[-1])//1 + 1)
        new_lunlun_numbers_list.append((1)*10**(ketasu-1))
        #10...1を入れる
        if ketasu !=2: #11の重複防止
            new_lunlun_numbers_list.append((1)*10**(ketasu-1)+1)


        if len(new_lunlun_numbers_list)+lunlun_numbers_numer >= K:
            new_lunlun_numbers_list.sort(reverse=False)
            print(new_lunlun_numbers_list[K-lunlun_numbers_numer-1])
            print(new_lunlun_numbers_list)
            break


        lunlun_numbers_list = copy.copy(new_lunlun_numbers_list)

Submission status: Wrong Answer

Solution code:
K=int(input())

from collections import deque
num=deque()
for i in range(1,10):
  num.append(i)

for j in range(K):
  l=num.popleft()
  if l%10 !=0:
    num.append(l*10+(l%10-1))
  num.append(l*10)
  if l%10 != 9:
    num.append(l*10+(l%10+1))

print(l)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
DATA = """
100000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()



def Calc():
	K = [int(i) for i in get_line().strip().split(" ")][0]
	ret = [str(_) for _ in range(1,10)]
	size = len(ret)
	start = 0
	print (ret)
	count = len(ret)
	while(size < K):
		for i in range(start, size):
			v = int(ret[i][-1])
			ll = ret[i]
			if not v == 0:
				count += 1
				ret.append(ll + str(v - 1))
			ret.append(ll + str(v))
			count += 1
			if not v == 9:
				count += 1
				ret.append(ll + str(v+1))

			if count >= K:
				break
		if count >= K:
			break
		start = size
		size = len(ret)
	print (ret[K-1])
Calc()

Submission status: Wrong Answer

Solution code:
from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
n=int(input())
def check(k):
  while k<=n:
    a=q.popleft()
    if a%10-1>=0:
      q.append(a*10+a%10-1)
      k=k+1 
      if k==n:
        return a*10+a%10-1
    k=k+1
    q.append(a*10+a%10)
    if k==n:
      return a*10+a%10
    if a%10+1<=9:
      q.append(a*10+a%10+1)
      k=k+1
      if k==n:
        return a%10+a%10+1
if n<=9:
  print(n)
else:
  print(check(9))

Submission status: Wrong Answer

Solution code:
from collections import deque
q=deque([1,2,3,4,5,6,7,8,9])
n=int(input())
def check(k):
  while k<n:
    a=q.popleft()
    if a%10-1>=0:
      q.append(a*10+a%10-1)
      k=k+1 
      if k==n:
        return a*10+a%10-1
    k=k+1
    q.append(a*10+a%10)
    if k==n:
      return a*10+a%10
    if a%10+1<=9:
      q.append(a*10+a%10+1)
      k=k+1
      if k==n:
        return a%10+a%10+1
if n<=9:
  print(n)
else:
  print(check(9))

Submission status: Wrong Answer

Solution code:
from itertools import takewhile

k = int(input())

def is_lunlun(i):
    l = [int(x) for x in list(str(i))]
    a = [abs(l[j] - l[j+1]) <= 1 for j in range(len(l)-1)]
        
    return all(a)

def lunlun():
    j = 1
    while True:
        if is_lunlun(j):
            yield j
        j += 1

print(k)
for i,e in enumerate(lunlun()):
    if i == k:
        print(e)
        break

Submission status: Wrong Answer

Solution code:
def next(a):
    if len(str(a))==1: 
        A=a+1
    else:
        for i in range(len(str(a))):
            if int(str(a)[-(i+2)]) - int(str(a)[-(i+1)]) ==0 or int(str(a)[-(i+2)]) - int(str(a)[-(i+1)]) ==1:
                A = a+1
                break
            elif int(str(a)[-(i+2)]) - int(str(a)[-(i+1)]) ==-1:
                A = a+10**(i+1) -10**i
                break
    return A

K =int(input())
a= 1
for i in range(K-1):
    a = next(a)
print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque
 
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
 
for i in range(k):
  a = q.popleft()
  if a % 10 == 0:
    q.append(10*a)
    q.append(10*a + 1)
  elif a % 10 == 9:
    q.append(10*a + 8)
    q.append(10*a + 9)
  else:
    q.append(10*a + a - 1)
    q.append(10*a + a)
    q.append(10*a + a + 1)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque
 
k = int(input())
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
 
for i in range(k):
  a = q.popleft()
  if a % 10 == 1:
    q.append(10*a)
    q.append(10*a + 1)
  elif a % 10 == 9:
    q.append(10*a + 8)
    q.append(10*a + 9)
  else:
    q.append(10*a + a - 1)
    q.append(10*a + a)
    q.append(10*a + a + 1)
else:
  print(a)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [x for x in range(1, 10)]

while(1):
    if(k <= len(a)):
        print(a[k-1])
        break
    k -= len(a)
    old = []
    old, a = a, old
    for x in old:
        for i in range(-1, 2):
            d = x % 10+1
            if(d < 0 or d > 9):
                continue
            nx = x*10 + d
            a.append(nx)

Submission status: Wrong Answer

Solution code:
k = int(input())
lunlun = [0,0,0,0,0,0,0,0,0,0,0,0]
for i in range(k):
    for i in range (len(lunlun)-1):
      if abs(lunlun[-i]-lunlun[-i-1])<1:
        lunlun[-1]+=1
        break
      else :
        lunlun[-i-1]+=1
        lunlun[-1]-=1
print("".join(map(str, lunlun)))

Submission status: Wrong Answer

Solution code:
def is_lunlun(x0, x1):
    return abs(int(x0) - int(x1)) <= 1
def minimize(s, j):
    start = int(s[-j])
    for i in range(j - 1,0,-1):
        if start != 0:
            start -= 1
            s[-i] = str(start)
        else:
            s[-i] = str(0)
    return s

k = int(input())
if (k <= 10):
    print(k)
else:
    counter = 10
    i = 10
    while counter < k:
        s = list(str(i + 1))
        if not is_lunlun(s[-2], s[-1]):
            for j in range(2, len(s) + 1):
                if s[-j] == '9':
                    s = minimize(s, j)
                else:
                    s[-j] = str(int(s[-j]) + 1)
                if j == len(s) or is_lunlun(s[-j], s[-(j + 1)]):
                    s = minimize(s, j)
                    break
            i = int("".join(s))
        else:
            i += 1
        counter += 1
    print(i)

Submission status: Wrong Answer

Solution code:
import queue

k=int(input())

q=queue.Queue()
for i in range(1,10):
    q.put(i)
cnt=0
ans=0

while cnt<k:
    ans=q.get()
    for i in range(-1,2):
        if 0<ans+i<10:
            q.put(ans*10+ans+i)
        else:
            continue
    cnt+=1

print(ans)

Submission status: Wrong Answer

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
                if i+1 > len(numlist)-1-2:
                    num= num+ 10**(len(numlist)-(i+1))
                break
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Wrong Answer

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
                if i+1 > len(numlist)-1-2:
                    num= num+ 10*(len(numlist)-(i+1))-1
                break
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Wrong Answer

Solution code:
k= int(input())
count= 0
num=1
if k<10:
    print(k)
else:
    while count != k:
        flag=0
        temp= str(num)
        numlist= list(temp)
        for i in range(0,len(numlist)-1):
            dis= int(numlist[i])-int(numlist[i+1])
            if abs(dis) >1:
                flag =1
                
                num= num+ 10*(i+1)-1
                break
        if flag==0:
            count= count+1
        num= num+1
    print(num-1)

Submission status: Wrong Answer

Solution code:
import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10))
  if ans%10!=0:
    q.put(10*ans+(ans%10)+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10)-1)
  if ans%10!=0:
    q.put(10*ans+(ans%10)+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10)-1)
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import queue
target = int(input())

q = queue.Queue()

for i in range(1,9):
  q.put(i)


for cnt in range(1, target - 1):
  num = q.get()
  mod = num % 10
  
  if mod == 0:
    q.put(num * 10)
    q.put(num * 10 + 1)
  elif mod == 9:
    q.put(num * 10 + 8)
    q.put(num * 10 + 9)
  else:
    q.put(num * 10 + mod - 1)
    q.put(num * 10 + mod)
    q.put(num * 10 + mod + 1)

print(q.get())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
K, = [int(s) for s in inputs]

# 100

if K<=9:
    print(K)
else:
    pre = list(range(10))
    digit = 0
    num = 9
    while True:
        lunluns = []
        for i in range(1, 10):
            for p in pre:
                s = p // (10**digit)
                if abs(i-s)<=1:
                    num += 1
                    lunlun = i*(10**(digit+1))+p
                    if K==num:
                        print(lunlun)
                        quit()
                    lunluns.append(lunlun)
        pre = lunluns
        #print(pre)
        digit += 1

Submission status: Wrong Answer

Solution code:
x=[0,1,2]
y=[3,4,5]
x+=y[:]
print(x)

Submission status: Wrong Answer

Solution code:
K=int(input())
lunlun=[1,2,3,4,5,6,7,8,9]
a=10
b=0
if K<10:
 a=(lunlun[K-1])
else:
  while True:
    for i in str(a):
      if abs(int(i)-b)>1:
        break
      else:
        b=int(i)
    else:
      lunlun.append(int(i))
    if len(lunlun)>=K:
    	break
    a += 1
print(a)

Submission status: Wrong Answer

Solution code:
K=int(input())
lunlun=[1,2,3,4,5,6,7,8,9]
a=10
b=0
if K<10:
  print(lunlun[K-1])
else:
  while True:
    for i in str(a):
      if abs(int(i)-b)>1:
        break
      else:
        b=int(i)
    else:
      lunlun.append(int(i))
    if len(lunlun)>=K:
    	break
    a += 1
print(a)

Submission status: Wrong Answer

Solution code:
LL = [i for i in range(1,13)]  
def kth_ll(K):
    count = 12
    num = 12
    if K <= len(LL):
        return LL[K - 1]

    flag = 1
    while K > count:
        num += 1

        for i in str(num):
            if i != str(num)[-1]:
                if abs(str(num)[i] - str(num)[i + 1]) > 2:
                    flag = 0
                break
    return num

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[1,2,3,4,5,6,7,8,9]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%10!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    ans = list(set(ans))
    if len(ans)>k:
        print(ans[k-1])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[1,2,3,4,5,6,7,8,9]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    ans = list(set(ans))
    if len(ans)>k:
        print(ans[k-1])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[1,2,3,4,5,6,7,8,9]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    if len(ans)>k:
        print(ans[k-1])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[1,2,3,4,5,6,7,8,9]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    if len(ans)>k:
        print(ans[k])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    if len(ans)>k:
        print(ans[k])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())
li=[[1,2,3,4,5,6,7,8,9]]
ans=[]
for i in range(9):
    tmp=[]
    for i2 in li[-1]:
        if i2%10!=0:
            tmp.append(i2*10+(i2%10-1))
            tmp.append(i2*10+(i2%10))
            ans.append(i2*10+(i2%10-1))
            ans.append(i2*10+(i2%10))
        if i2%19!=9:
            tmp.append(i2*10+(i2%10+1))
            ans.append(i2*10+(i2%10+1))
            li.append(tmp)
    if len(ans)>k:
        print(ans[k-1])
        break

Submission status: Wrong Answer

Solution code:
k = int(input())

flag = True
f = False
def judge(i):
	q = i //10
	r = i % 10
	while True:
		if q % 10 == 0:
			f = True
			break
		else:
			if abs(r -(q%10)) <= 1:
				q = q // 10
				r = q % 10
				continue
			else:
				f = False
				break
	return f

i = 1
while flag:
	if judge(i):
		k -= 1
		i += 1
	else:
		i+=1
		continue
	if k == 0:
		print(i-1)
		flag = False

Submission status: Wrong Answer

Solution code:
import queue

n = int(input())


q = queue.Queue()

for i in range(1,10):
    q.put(i)

x = 0
for i in range(n):
    x = q.get()
    l = x % 10
    print(x,l)
    if l != 0:
        q.put(x*10 + l - 1)
    q.put(x*10 + l)
    if l != 9:
        q.put(x*10 + l + 1)
        
#while not q.empty():
#    print (q.get())
    
print(x)

Submission status: Wrong Answer

Solution code:
from collections import deque
K = int(input())
Q = deque([i for i in range(1,10)])

for _ in range(K-1):
  q = Q.popleft()
  if q%10 != 0:
    Q.append(q*10+q%10-1)
  Q.append(q*10+q%10)
  if q%9 != 0:
    Q.append(q*10+q%10+1)
print(Q.popleft())

Submission status: Wrong Answer

Solution code:
from collections import deque


k = int(input())
d = deque([1,2,3,4,5,6,7,8,9])

for i in range(k):
    a = d.popleft()
    if a % 10 != 0:
        d.append(a*10 + a % 10 - 1)
    d.append(a*10 + a % 10)
    if a % 10 != 9:
        d.append(i*10 + i % 10 + 1)

print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque


k = int(input())
d = deque([1,2,3,4,5,6,7,8,9])

for i in range(k):
    a = d.popleft()
    d.append(i*10 + i % 10 - 1)
    d.append(i*10 + i % 10)
    if a != 9:
        d.append(i*10 + i % 10 + 1)

print(a)

Submission status: Wrong Answer

Solution code:
from collections import deque


k = int(input())
d = deque([1,2,3,4,5,6,7,8])

for i in range(k):
    a = d.popleft()
    d.append(i*10 + i % 10 - 1)
    d.append(i*10 + i % 10)
    if a != 9:
        d.append(i*10 + i % 10 + 1)

print(a)

Submission status: Wrong Answer

Solution code:
def is_lunlun(i):
    list_i = list(str(i))
    for j in range(len(list_i)-1):
        if int(list_i[j]) == 0:
            if int(list_i[j+1]) not in [1,9,0]:
                return False
        elif int(list_i[j]) == 1:
            if int(list_i[j+1]) not in [0,1,2]:
                return False
        elif int(list_i[j]) == 9:
            if int(list_i[j+1]) not in [8,9]:
                return False
        else:
            if abs(int(list_i[j]) - int(list_i[j+1])) > 1:
                return False
    return True



if __name__ == '__main__':
    k = int(input())
    lunlun = (i for i in range(3234566667) if is_lunlun(i))
    for count, i in enumerate(lunlun):
        if count == k:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
def is_lunlun(i):
    list_i = list(str(i))
    for j in range(len(list_i)-1):
        if int(list_i[j]) == 0:
            if int(list_i[j+1]) not in [1,9,0]:
                return False
        elif int(list_i[j]) == 1:
            if int(list_i[j+1]) not in [0,1,2]:
                return False
        elif int(list_i[j]) == 9:
            if int(list_i[j+1]) not in [0,8,9]:
                return False
        else:
            if abs(int(list_i[j]) - int(list_i[j+1])) > 1:
                return False
    return True



if __name__ == '__main__':
    k = int(input())
    lunlun = (i for i in range(3234566667) if is_lunlun(i))
    for count, i in enumerate(lunlun):
        if count == k:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
def is_lunlun(i):
    list_i = list(str(i))
    for j in range(len(list_i)-1):
        if int(list_i[j]) == 0:
            if int(list_i[j+1]) not in [1,9,0]:
                return False
        elif int(list_i[j]) == 1:
            if int(list_i[j+1]) not in [0,1,2]:
                return False
        elif int(list_i[j]) == 9:
            if int(list_i[j+1]) not in [0,8,9]:
                return False
        else:
            if abs(int(list_i[j]) - int(list_i[j+1])) > 1:
                return False
    return True



if __name__ == '__main__':
    k = int(input())
    lunlun = (i for i in range(3234566667) if is_lunlun(i))
    for count, i in enumerate(lunlun):
        if count == k-1:
            print(i)
            break

Submission status: Wrong Answer

Solution code:
K = int(input())
i = 10
l= 0
lunlunlist = []

while all:
    l += 1 
    lunlunlist.append(l)
    if(l == 9):
        break
    
while all:
    if(len(lunlunlist)>=K):
        break
    i_str = str(i)
    array = list(map(int,i_str))
    j=0
    f=0
    for j in range(len(array)-1):
        if(abs(array[j]-array[j+1])>1):
            f = 1
            break
    if(f==0):
        lunlunlist.append(i)
    i+=1
if(K<=9):
    print(lunlunlist[K-1])
print(lunlunlist,lunlunlist[-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
a = deque([1,2,3,4,5,6,7,8,9])
count=0
while count !=k:
  b = a.popleft()
  count += 1
  if b%10==0:
    a.append(b*10)
    a.append(b*10+1)
  elif b%9==0:
    a.append(b*11-1)
    a.append(b*10+9)
  else:
    a.append(b*10+b%10-1)
    a.append(b*10+b%10)
    a.append(b*10+b%10+1)
print(b)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[i+1 for i in range(9)]
while (1):
  if k<=len(a):
    print(a[k-1])
    f=1
    break
  
  k=k-len(a)
  #print(k)
  b=[]
  for x in a:
    for i in [-1,0,1]:
      d=x%10+i
      #print(d)
      if d<0 or d>10: continue
      b.append(x*10+d)
  a=b.copy()

Submission status: Wrong Answer

Solution code:
n = int(input())


queueList = []
oldList = []
for i in range(10):
	queueList.append(i)
# print(queueList)
if n < len(queueList):
	print(queueList[:n])
	exit()
while(True):
	headElement = queueList[0]
	queueList.pop(0)
	oldList.append(headElement)
	for i in range(-1,2):
		newElement = headElement % 10 + i
		if newElement < 0 or 9 < newElement:
			continue
		if not (headElement*10 + newElement in oldList or headElement*10 + newElement in queueList):
			queueList.append(headElement*10 + newElement)
	if len(oldList) == n:
		break

print(sum(oldList))