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: Time Limit Exceeded

Solution code:
def main():
    K = int(input())

    lunlun_number_memo = {}

    # def is_lunlun(str_n):
    #     while True:
    #         if lunlun_number_memo.get(str_n):
    #             return True
    #         elif len(str_n) == 1:
    #             return True
    #         else:
    #             if abs(int(str_n[0]) - int(str_n[1])) <= 1:
    #                 str_n = str_n[1:]
    #             else:
    #                 return False


    lunlun_number_count = 0
    i = 0
    while lunlun_number_count < K:
        i += 1
        # if is_lunlun(str(i)):
        str_i = str(i)
        while True:
            if lunlun_number_memo.get(str_i) or len(str_i) == 1:
                lunlun_number_memo[str(i)] = True
                lunlun_number_count += 1
            else:
                if abs(int(str_i[0]) - int(str_i[1])) <= 1:
                    str_i = str_i[1:]
                else:
                    break

            # print(i)
            # print(lunlun_number_count)
            # print("running")

    print(i)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def digit(num):
    num_list = list(str(num))

    i = 0
    while i < len(num_list) - 1:
        if abs(int(num_list[i]) - int(num_list[i + 1])) > 1:
           return False
        i += 1
    return True

k = int(input())

run = 0
run_n = 1
num = 1


while run_n <= k:
    if digit(num) == True:
        run = num
        run_n += 1
        num += 1
    else:
        num += 1


print(run)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

cnt = 0
n = 1
while cnt != k:
  if n < 13:
    cnt += 1
  else:
    for i in range(len(str(n))-1):
      if abs(n%(10**(i+1)) - n%(10**(i+2))) > 1:
        break
    else:
      cnt += 1
  
  n += 1

print(n-1)

Submission status: Time Limit Exceeded

Solution code:
i = int(input())
p = 11
count = 10
if i < 11:
  print(i)
else:
  i = 1 - 10
  while i != count:
    x = str(p).split()
    l = len(x) - 2
    j = 0
    for f in range(l):
      if abs(int(x[f]) - int(x[f+1])) > 1:
        j = 1
    if j == 0:
      count += 1
    p += 1
  print(count)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

hantei = 1
X = 99
num = 35
runrun = 99

if K <= 35:
    kotae = [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,99]
    runrun = kotae[K - 1]

else:
    while num <= K:
        Xstr = str(X)
        Xlist = list(map(int, Xstr))
        
        for i in range(len(Xlist) - 1):
            if not ((Xlist[i] - Xlist[i + 1] == -1) or (Xlist[i] - Xlist[i + 1] == 0) or (Xlist[i] - Xlist[i + 1] == 1)):
                hantei = 0
            

        if hantei == 1:
            num += 1
            runrun = X

        else:
            hantei = 1
        
        X += 1
        
print(runrun)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
j=0
c=0
while c<=n:
  j+=1
  b=0
  if j<10:
    c+=1
    if c==n:
      break
  else:
    a=str(j)
    for i in range(len(a)-1):
      if abs(int(a[i])-int(a[i+1]))<=1:
        b+=1
    if b==len(a)-1:
      c+=1
    if c==n:
      break
print(j)

Submission status: Time Limit Exceeded

Solution code:
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

Submission status: Time Limit Exceeded

Solution code:
def get_lunlun(x):
    while(True):
        x+=1
        if check_lunlun(x):
            return x

# 下の桁から確認し、lunlunかチェック
def check_lunlun(x):
    while(True):
        i = x%10
        j = (x//10)%10
        if abs(i-j)<=1:
            pass
        else:
            return False
        x = x//10
        if x<10:
            return True
K = int(input())
if K<10:
  print(K)
else:
  result = [1,2,3,4,5,6,7,8,9]
  now = 9
  for i in range(10,K+1):
      now = get_lunlun(now)
      result.append(now)
  print(now)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import sys
sys.setrecursionlimit(1000000)
run = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def runrun(number):
    if len(number) < 12:
        last = int(number[-1])
        if last == 0:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
        elif last == 9:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])-1))
        else:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
            runrun(str(int(number[-1])-1))


for i in range(1, 10):
    runrun(str(i))
run.sort(reverse=False)
print(run[K-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
if(k < 10):
    print(k)
else:
    n = 9
    p = 9
    while(p < k):
        n += 1
        t = str(n)
        x = 0
        for i in range(len(t)-1):
            if(abs(int(t[i])-int(t[i+1])) > 1):
                x = 1
        if(x == 0):
            p += 1
        
    print(n)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

def check_runrun(x):
    tmp = list(map(int, list(str(x))))
    pre = tmp[0]
    for i in tmp:
        if abs(pre - i) > 1:
            return False
        pre = i
    return True


def next_runrun(x):
    pre_x = x
    while True:
        x += 1
        if check_runrun(x):
            return x
        pre_x = x

cnt = 0
x = 1

while cnt < K-1:
    x = next_runrun(x)
    cnt += 1

print(x)

Submission status: Time Limit Exceeded

Solution code:
import itertools
k=int(input())
l=[[1,2,3,4,5,6,7,8,9]]
for _ in range(10):
  a=[]
  for i in range(len(l[-1])):
    L=l[-1][i]
    if L%10==9:
      a.append(L*10+8)
      a.append(L*10+9)
    elif L%10==0:
      a.append(L*10+0)
      a.append(L*10+1)
    else:
      a.append(L*10+L%10-1)
      a.append(L*10+L%10)
      a.append(L*10+L%10+1)
    l.append(a)
print(sorted(set(list(itertools.chain.from_iterable(l))))[k-1])

Submission status: Time Limit Exceeded

Solution code:
K=int(input())
i=0
current_num=0
while (i<K) :
  current_num+=1
  current_string=str(current_num)
  flag=True
  for k in range(len(current_string)-1) :
    if abs(int(current_string[k])-int(current_string[k+1]))>1 :
      flag=False
      break
  if flag==True :
    i+=1
  
  
print(current_num)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

def check(num):
    elems = str(num)
    flag = 0
    for elem1, elem2 in zip(elems[:-1], elems[1:]):
        if abs(ord(elem1) - ord(elem2)) <= 1:
            pass
        else:
            flag = 1
            break
    if flag == 0:
        return num
    else:
        return -1

i = 1
lst = []
while len(lst) < k:
    res = check(i)
    if res != -1:
        lst.append(res)
    i += 1
print(lst[-1])

Submission status: Time Limit Exceeded

Solution code:
k=input()
n=len(k)
cnt=9
def lunlun(x):
    flag=True
    x=str(x)
    for num in range(len(x)-1):
        a=x[num]
        b=x[num+1]
        if abs(int(a)-int(b))>1:
            flag=False
            break
    return flag
i=9
if n==1:
    print(k)
else:
    while cnt!=k:
        i+=1
        if lunlun(i):
            cnt+=1
    print(i)

Submission status: Time Limit Exceeded

Solution code:
"""
K正の整数 X が以下の条件を満たすとき、 X はルンルン数であると言います。

X を(leading zeroなしで)十進数表記した際に、
隣り合うどの 2 つの桁の値についても、差の絶対値が 1 以下

例えば、 1234 , 1 , 334 などはルンルン数ですが、 
31415 , 119 , 13579 などはルンルン数ではありません。
正の整数 K が与えられます。小さい方から K 番目のルンルン数を求めてください。
"""
import sys
#print(sys.maxsize)

import math
k=int(input())
#n,k=map(int,input().split())
i=1
l=1
while l<=k:
  stri=str(i)
  #print("stri: "+stri)
  judge=0
  a0=stri[0]
  for ia,a in enumerate(stri):
    if ia!=0:
      x=abs(int(stri[ia-1])-int(a))
      #print(x)
      if(x>1):
        judge=judge+1
      #print(a,stri[ia-1])
    #print(ia,a)
  #print(i, judge)
  if judge==0:
    l=l+1
  i=i+1
print(i-1)
"""
xi1=abs(xi-k)
leap=math.floor(xi1/k)-3
xi1,xi=abs(xi1-k*leap),xi1
while ((i==0)|(xi1 < xi)) :
  #print(i)
  if(math.floor(i/100000)==0):
    print(xi1,xi)
  xi1,xi=abs(xi1-k),xi1
  i=i+1
#print("xi1: "+ str(xi1))
print(xi)
"""  

"""
#b=sorted(a, reverse=True)
#print(sum(b))
if b[m-1]>= (sum(b) /(4*m)) :
  print("Yes")
else:
  print("No")

x,y,z=map(int,input().split())
a,b,c=x,y,z
a,b=b,a
a,c=c,a
print(a,b,c)
"""

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import sys
sys.setrecursionlimit(1000000)
run = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def runrun(number):
    if len(number) < 14:
        last = int(number[-1])
        if last == 0:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
        elif last == 9:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])-1))
        else:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
            runrun(str(int(number[-1])-1))


for i in range(1, 10):
    runrun(str(i))
run.sort(reverse=False)
print(run[K-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

count = 9

i = 10
while True:
    if K<=9:
        ans = K
        break
    
    for j in range(1,len(str(i))):
        num1 = str(i)[j-1]
        num2 = str(i)[j]

        if abs(int(num1)-int(num2))>1:
            break

        if j == len(str(i))-1:
            count +=1
         
    if count == K:
        ans = i
        break
    else:
        i+=1
   

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
count = 0
def check(x):
    f= True
    if(x < 10):
        return True
    x = str(x)
    for i in range(len(x)-1):
        if( int(x[i]) - int(x[i + 1]) == 0):
            x = x
        elif( int(x[i]) - int(x[i + 1]) == 1 ):
             x = x
        elif( int(x[i]) - int(x[i + 1]) == -1 ):
             x = x
        else:
            return False

    return True
i = 0    
while(True):
    i = i + 1
    if(check(i)):
    #    print(i)
        count = count + 1 
        if(count == num ):
            print(i)
            exit()

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

runrun = 0
N = 0
while runrun < K:
    N = N + 1
    a = N
    b = 0
    while a >= 1:
        a = a / 10
        b = b + 1

    if b == 1:
        runrun = runrun + 1
    else:
        e = 0
        for i in range(b - 1):
            M = str(N)
            c = int(M[b - 1 - i])
            d = int(M[b - 2 - i])
            if c - d < -1 or 1 < c - d:
                e = 1
        if e == 0:
            runrun = runrun + 1
print(N)

Submission status: Time Limit Exceeded

Solution code:
li = list(map(int, input().split()))
k = li[0]
a = 9
r = [1, 2, 3, 4, 5, 6, 7, 8, 9]

i = 10
while True:
    if k < 10:
        break
    j = 0
    if a == k:
        break
    l = list(str(i))
    l_i = [int(s) for s in l]
    for x in range(0, len(l_i)-1):
        if abs(l_i[x] - l_i[x + 1]) <= 1:
            j += 1
    if j + 1 == len(l_i):
        r.append(i)
        a+=1
    i += 1
print(r[k-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

li=[]

for i in range(1,10):
    li.append(i)
for i in range(10,100):
    if abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(100,1000):
    if abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(1000,10000):
    if abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(10000,100000):
    if abs(int(str(i)[3])-int(str(i)[4]))<2 and abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(100000,1000000):
    if abs(int(str(i)[4])-int(str(i)[5]))<2 and abs(int(str(i)[3])-int(str(i)[4]))<2 and abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(1000000,10000000):
    if abs(int(str(i)[5])-int(str(i)[6]))<2 and abs(int(str(i)[4])-int(str(i)[5]))<2 and abs(int(str(i)[3])-int(str(i)[4]))<2 and abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(10000000,100000000):
    if abs(int(str(i)[6])-int(str(i)[7]))<2 and abs(int(str(i)[5])-int(str(i)[6]))<2 and abs(int(str(i)[4])-int(str(i)[5]))<2 and abs(int(str(i)[3])-int(str(i)[4]))<2 and abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
for i in range(100000000,1000000000):
    if abs(int(str(i)[7])-int(str(i)[8]))<2 and abs(int(str(i)[6])-int(str(i)[7]))<2 and abs(int(str(i)[5])-int(str(i)[6]))<2 and abs(int(str(i)[4])-int(str(i)[5]))<2 and abs(int(str(i)[3])-int(str(i)[4]))<2 and abs(int(str(i)[2])-int(str(i)[3]))<2 and abs(int(str(i)[1])-int(str(i)[2]))<2 and abs(int(str(i)[0])-int(str(i)[1]))<2:
           li.append(i)
                    
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
if K < 10:
  print(K)
if K >= 10:  
  a = 9
  flag = False
  for i in range(10, 10**9+1):
    if a < K:
      b = 0
      for j in range(len(str(i)) -1):
        if abs(int(str(i)[j]) - int(str(i)[j+1])) <= 1:
          b += 1
          if b == len(str(i))-1:
            a += 1
            if a == K:
              print(i)
              flag = True
              break
      if flag:
        break

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
c = 0
x = 0
sx = 0
while c < k:
  x+=1
  sx = str(x)
  c+=1
  for i in range(len(sx)-1):
    if abs(int(sx[len(sx)-1 -i]) - int(sx[len(sx)-2-i])) > 1:
     c-=1
     break
print(x)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
c = 1
i = 1
while c != K:
  i += 1
  S = str(i)
  l = len(S) - 1
  for j in range(l):
    if abs(int(S[j]) - int(S[j+1])) > 1:
      break
  else:
    c += 1    
print(i)

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

cnt = 0
runrun = [1,2,3,4,5,6,7,8,9,10]

i = 1
judge = True
while judge:
    lnum = list(str(i))
    div = True
    for j in range(len(lnum)):
        if len(lnum) == 1:
            break

        str_num = lnum[j:j+2]
        if str_num in runrun:
            next
        else:
            if len(lnum) > 3:
                div = False
                break

        now = lnum[j]
        nxt = (j+1) % len(lnum)
        if nxt == 0:
            break
        nxt = lnum[nxt]

        sum_num = int(now) - int(nxt)
        if abs(sum_num) > 1:
            div = False
            break

    if div:
        cnt += 1
        if cnt == k:
            print(i)
            judge = False
            exit
        runrun.append(str(i))

    i += 1

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
i,j = 0,1
while i<k:
  if j<10: i+=1
  else:
    lis = [int(x) for x in list(str(j))]
    for m in range(len(lis)-1):
      if abs(lis[m+1]-lis[m])<2: continue
      else: 
        i-=1
        break
    i+=1
  j+=1
print(j-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
import sys
sys.setrecursionlimit(1000000)
run = [1, 2, 3, 4, 5, 6, 7, 8, 9]


def runrun(number):
    if len(number) < 16:
        last = int(number[-1])
        if last == 0:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
        elif last == 9:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])-1))
        else:
            run.append(int(str(int(number[-1])+0)))
            run.append(int(str(int(number[-1])-1)))
            run.append(int(str(int(number[-1])+1)))
            runrun(str(int(number[-1])+0))
            runrun(str(int(number[-1])+1))
            runrun(str(int(number[-1])-1))


for i in range(1, 10):
    runrun(str(i))
run.sort(reverse=False)
# print(len(run))
# print(run[:20])
print(run[K-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

n = 3234566668

l = []
for i in range(1, n):
    flag = 0
    s = str(i)
    for j in range(1, len(s)):
        if abs(int(s[j]) - int(s[j-1])) > 1:
            flag = 1
            break
    if flag == 0:
        l.append(i)
    if len(l) == k:
        break
print(l[k-1])
kkk = ""
for i in range(len(str(k))-1):
    kkk += "1"
kkk += "0"
# print(l[k-1]-int(kkk))
# print(l)

Submission status: Time Limit Exceeded

Solution code:
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

Submission status: Time Limit Exceeded

Solution code:
k=int(input())
num=0

while k>0:
  num+=1
  snum=str(num)
  flg=0
  for i in range(0,len(snum)-1):
    if abs(int(snum[-1-i])-int(snum[-2-i]))>1:  
      flg=1
      break
  if flg==0:
    k-=1
print(num)

Submission status: Time Limit Exceeded

Solution code:
def lunlun(num):
    output = True
    st_num = str(num)
    for ind in range(len(str(num))-1):
        output = output * (abs(int(st_num[ind])-int(st_num[ind+1])) <= 1)
    return output
        
k = int(input())
num = 0
for ind in range(k):
    num += 1
    while not lunlun(num):
        num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
k = int(input())

def gen(n):
    if n < 10:
        yield n
    else:
        for m in gen(n/10):
            yield m
        yield n%10
c = 9
if k >= 10:
    for i in range(10, 10**5):
        a = np.array( [int(i) for i in gen(i)])
        b = np.diff(a)
        if max(abs(b)) <= 1:
            c = c + 1
        if c == k:
            break

if k <= 10:
    print(k)
else:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
def check(a):
    if len(str(a)) == 1:
        return True
    a = list(str(a))
    b = [abs(int(a[i]) - int(a[i + 1])) for i in range(len(a) - 1)]
    if max(b) > 1:
        return False
    else:
        return True

k = int(input())
a = 0
while True:
    a += 1
    if check(a):
        k -= 1
    if k == 0:
        print(a)
        exit()

Submission status: Time Limit Exceeded

Solution code:
k = int(input())

count = 0

for i in range(1,10**10):
    l = len(str(i))
    if l == 1:
        count +=1
        ans = i
        if count == k:
            print(ans)
            break
        else:
            continue
    else:
        for j in range(l-1):
            if not abs(int(str(i)[j]) - int(str(i)[j+1])) <= 1:
                continue
            elif j ==l-1:
                count +=1
                ans = i
    if count == k:
        print(ans)
        break

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
cnt = 24
s = 0
while 1:
    for i in range(len(str(cnt))):
        if (s!=0)and(int(str(cnt))[i]-int(str(cnt))[i-1])<=1:
            s += 1
            print(cnt)
        
    
    if s==K:
        print(cnt)
        break
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
def is_lunlun(n):
    m = str(n)
    for i in range(1,len(m)):
        if abs(int(m[i]) - int(m[i-1])) > 1:
            return False
    return True

def main():
    K = int(input())
    A = [i for i in range(100000) if is_lunlun(i)]
    B = [int(str(a1)+str(a2)) for a1 in A for a2 in A if is_lunlun(int(str(a1)+str(a2))) and int(str(a1)+str(a2)) < 3234566668]
    B2 = sorted(set(B))
    print(B2[K])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
sk=input()
k = int (sk)
wk=[[0]*10]*12
wk[1]=[0,1,1,1,1,1,1,1,1,1]
wk[2]=[1,2,3,3,3,3,3,3,3,2]
k3=[2,3,3,3,3,3,3,3,3,2]
#print(wk[1])
if k <= 11 :
  print(k)
sumk = 0
for i in range(3,10):
  for j in range(10):
    wwkk = wk[i-1][j]*k3[j]
    wk[i][j] = wwkk
    sumk += wwkk
  #print(sumk)
#exit()
for n in range(12,10000000):
  strn = str(n)
  lstn = [int(e) for e in strn]
  rt = True
  for j in range( len(lstn)-1 ):
    df = abs(lstn[j] - lstn[j+1])
    if df > 1 :
      rt = False
      break
  if rt:
    k -= 1
    if k == 11 :
      print(n)
      break

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
b=0
ans="1"

while True:
    ok=True
    for i in range(len(ans)-1):
        if abs(int(ans[i])-int(ans[i+1]))>1:
            ok=False
            break
    if ok:
        b+=1
        if b==a:
            print(ans)
            break
    ans=str(int(ans)+1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

n = 1
s = 9 * 2 ** (n - 1)
while s < K:
    n = n + 1
    s = 9 * 2 ** (n - 1)

result = []


def bianli(currentIndex, currentValue, currentValueStr, maxLevel):
    if currentIndex < maxLevel:

        nextIndex = currentIndex + 1

        result.append(int(currentValueStr))

        bianli(nextIndex, currentValue, "{}{}".format(currentValueStr, currentValue), maxLevel)

        if currentValue == 0:
            nextValue = 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
        elif currentValue == 9:
            nextValue = 8
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
        else:
            nextValue = currentValue + 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)
            nextValue = currentValue - 1
            bianli(nextIndex, nextValue, "{}{}".format(currentValueStr, nextValue), maxLevel)

    else:
        result.append(int(currentValueStr))


bianli(1, 1,"1", n)
bianli(1, 2,"2", n)
bianli(1, 3,"3", n)
bianli(1, 4,"4", n)
bianli(1, 5,"5", n)
bianli(1, 6,"6", n)
bianli(1, 7,"7", n)
bianli(1, 8,"8", n)
bianli(1, 9,"9", n)

print(sorted(result)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

K = int(input())
d = defaultdict(int)

if K<10:
    print(K)
    exit()

# i: 0~99
# j: 0~8
dp = [[0]*10 for _ in range(20)]
for i in range(10):
    dp[0][i] = 1

end = False
# morau DP
i = 1
cnt = 9
while 1:
    #print('i: ', i)
    #pri(dp)
    for j in range(10):
        #print('j: ', j)
        if end:
            break
        if j==0:
            dp[i][j] += dp[i-1][j]
            dp[i][j] += dp[i-1][j+1]
        elif j==9:
            dp[i][j] += dp[i-1][j-1]
            dp[i][j] += dp[i-1][j]
        else:
            dp[i][j] += dp[i-1][j-1]
            dp[i][j] += dp[i-1][j]
            dp[i][j] += dp[i-1][j+1]

        if j!=0:
            addval = dp[i][j]
        else:
            addval = 0

        #print(' i, j, cnt, addval:', i, j, cnt, addval)
        if cnt+addval>=K:
        #if dp[i][j]>=K and j!=0:
            end = True
            break
        else:
            cnt += addval
    if end:
        break
    i += 1

#pri(dp)
#print(i, j, cnt)

def check(i, val): # i+1 桁の数が来る
    sval = str(val)
    for k in range(i):
        aa = abs(int(sval[k])-int(sval[k+1]))
        if aa>1:
            return False
    else:
        return True

val = 10**i*j
while cnt<K:
    #print(' val:', val)
    if check(i, val):
        cnt += 1
    val += 1
        
print(val-1)

Submission status: Time Limit Exceeded

Solution code:

def isLunlun(n):

  s = str(n)

  prev = ""

  for c in s:

    if prev == "" or abs(int(c) - int(prev)) <= 1:

      pass

    else:

      return False

    prev = c

  return True





def lunlunN(k):

  n = 0

  count = 0

  i = 1

  while True:

    if isLunlun(i):

      n = i

      count += 1

    i += 1

    if count >= k:

      return n



K = int(input())

print(lunlunN(K))

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

K = int(read().rstrip())

def F(S):
    left = None
    for i, s in enumerate(list(S)):
        if left is None:
            left = s
            continue

        x = abs(int(left) - int(s))
        if x > 1:
            # if left < s:
            #     return False, i
            # return False, None
            return False, i
    return True, None

def ceil(num, keta):
    list_i = list(str(num))
    if int(list_i[keta-1]) < int(list_i[keta]):
        left = str(int("".join(list_i[:keta])) + 1)
    else:
        left = "".join(list_i[:keta])
    right = "0" * (len(list_i) - 1 - keta)
    right_first = str(int(left[-1]) - 1)
    n = left + right_first + right
    # print("{}->{} left: {} right: {}".format(num, n, left, right))
    return int(n)

runrun_number = 0
i = 0
while True:
    i += 1
    is_runrun, keta = F(str(i))
    if is_runrun:
        # print(i)
        runrun_number += 1
        if runrun_number == K:
            answer = i
            break
        continue
    i = ceil(i, keta) - 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())

flags = [-1] * (10**8+7)

count = 0
now = 1
flags[0] = 1
while count != K:
    if now < 10:
        flags[now] = 1
    elif now < 100:
         if abs((now % 10) - (now // 10)) <= 1:
             flags[now] = 1
         else:
             flags[now] = 0
    else:
        n = int(str(now)[1:])
        if len(str(now)[1:]) != len(str(n)):
            if int(str(n)[0]) == 1 or int(str(n)[0]) == 0:
                if flags[n]:
                    if abs(int(str(now)[0]) - int(str(now)[1])) <= 1:
                        flags[now] = 1
                    else:
                        flags[now] = 0
                else:
                    flags[now] = 0
            else:
                flags[now] = 0
        else:
            if flags[n]:
                if abs(int(str(now)[0]) - int(str(now)[1])) <= 1:
                    flags[now] = 1
                else:
                    flags[now] = 0
            else:
                flags[now] = 0
    if flags[now] == 1:
        count += 1
        # print(now)
    # print('count: {}, now: {}, flag: {}'.format(count, now, flags[now]))
    now += 1

print(now - 1)