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())
no_runrun = False
ans = 0
if k < 10:
    print(k)
    exit()
else:
    k -= 9
for n in range(2,11):
    if k > 9 * (3 ** (n-1)) - (2 ** (3 * (n-2))):
        k -= 9 * (3 ** (n-1)) - (2 ** (3 * (n-2)))
    else:
        for i in range(10**(n-1), 10**n):
            num = [int(s) for s in list(str(i))]
            for x in range(len(num)-1):
                if abs(num[x]-num[x+1]) > 1:
                    no_runrun = True
                    break
            if not no_runrun:
                k -= 1
                ans = int(''.join(map(str, num)))
            no_runrun = False
            if k == 0:
                print(ans)
                exit()

Submission status: Wrong Answer

Solution code:
k = int(input()) - 1

keta = 1
keta_list = [9]

while k > 0:
    k -= 1
    for i in range(keta):
        if keta_list[i] != 0:
            keta_list[i] -= 1
            for j in range(i):
                keta_list[j] = 2
            break
    if keta == 1 and keta_list == [0]:
        keta_list = [1]*(keta-1)+[2, 9]
        keta += 1
    if keta_list[0] == 0 and keta_list[1:] == [1]*(keta-1) and keta > 1:
        keta_list = [1]*(keta-1)+[2, 9]
        keta += 1
pre = 10-keta_list[-1]
answer = str(pre)
for num in reversed(keta_list[:-1]):
    pre = pre+1-num
    pre = pre * (pre>0)
    answer += str(pre)
print(answer)

Submission status: Wrong Answer

Solution code:
from collections import deque

k = int(input())

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

for n in range(0, k):
  x = que.popleft()
  if x % 10 != 0:
    que.append(x * 10 + x % 10 - 1)
  que.append(10*x)
  if x % 10 != 9:
    que.append(x * 10 + x % 10 + 1)

print(x)

Submission status: Wrong Answer

Solution code:
K = int(input())

q = [1,2,3,4,5,6,7,8,9]
i = 0
n = 9
while n < K:
    x = q[i]
    if x % 10 > 0:
        q.append(x * 10 + x - 1)
        n += 1
    q.append(x * 10 + x)
    n += 1
    if x % 10 < 9:
        q.append(x * 10 + x + 1)
        n += 1
    i += 1
print(q[K-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
K = int(input())

q = [1,2,3,4,5,6,7,8,9]
i = 0
n = 0
while n < K:
    x = q[i]
    if x % 10 > 0:
        q.append(x * 10 + x - 1)
        n += 1
    q.append(x * 10 + x)
    n += 1
    if x % 10 < 9:
        q.append(x * 10 + x + 1)
        n += 1
    i += 1
print(q[K])

Submission status: Wrong Answer

Solution code:
k=int(input())
x=0
ans=0
for i in range(1,10**5):
  if x==k:
    break
  ans+=1
  l = [int(x) for x in list(str(i))]
  y=0
  for j in range(int(len(l))-1):
    if l[j]==l[j+1] or l[j]==l[j+1]+1 or l[j]==l[j+1]-1:
      y+=1
  if y==int(len(l))-1:
    x+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#n桁のるんるん数のrisutoを求める
import sys

sys.setrecursionlimit(10**9)

def runrun(n):
    if n == 1:
        return [['1','2','3','4','5','6','7','8','9']]
    else:
        li = runrun(n-1)
        li2 = []
        for i in range(len(li[n-2])):
            p = int(li[n-2][i][-1])
            if p == 0:
                li2.append(li[n-2][i]+'0')
                li2.append(li[n-2][i]+'1')
            elif p == 9:
                li2.append(li[n-2][i]+str(8))
                li2.append(li[n-2][i]+'9')
            else:
                li2.append(li[n-2][i]+str(p-1))
                li2.append(li[n-2][i]+str(p))
                li2.append(li[n-2][i]+str(p+1))
        li2 =[li2]
        li.extend(li2)
        return li
    


x = int(input())
t = True
k=1
b = 0
while t:
    a = runrun(k)
    b = 0
    #k桁までに何個るんるん数があるか数えるもの
    for i in range(len(a)):
        b+=(len(a[i]))
        #k桁ということが確定したあと以下の処理を行う
    if x <= b:
        t = False
        if k == 1:
            print(x)
        else:
            tmp = runrun(k-1)
            c = 0
#まずk-1桁までのるんるん数の数を数える
            for i in range(len(tmp)):
                c += (len(tmp[i]))
            s = a[k-1][x-c-1]
            print(int(s))
    else:
        k += 1
        print(b)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
K  =int(input())
import heapq
q = []
for i in range(1,10):
    heapq.heappush(q,(i))

cnt = 0
while True:
    cnt += 1
    a = heapq.heappop(q)
    if a > 0:
        add = str(a-1)
        heapq.heappush(q, int(str(a)+add))
    if a < 9:
        add = str(a+1)
        heapq.heappush(q, int(str(a)+add))
    heapq.heappush(q, int(str(a)+str(a)))           
    if cnt == K:
        print(a)
        exit()

Submission status: Wrong Answer

Solution code:
print("yippe")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
queue = deque(queue)
L = []
cnt = 0
while cnt <= K:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v + v[-1])
        queue.append(v+str(t+1))
    cnt += 1
print(v)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

if N <= 12:
    print(N)
else:
    str_ans = "12"
    counter = 12
    while counter < N:
        len_ans = len(str_ans)
        low_nine_num = 0
        for i in range(len_ans):
            if str_ans[len_ans - i - 1] == "9":
                low_nine_num += 1
            else:
                break
        if low_nine_num == len_ans:
            str_ans = "1" + "0" * len_ans
        else:
            chenged_top_num = 0
            low_digit_num = 0
            if low_nine_num == len_ans - 1:
                chenged_top_num = int(str_ans[len_ans - low_nine_num - 1])
                low_digit_num = len_ans - 1
            else:
                for i in range(len_ans - low_nine_num):
                    if i == len_ans - low_nine_num - 1:
                        chenged_top_num = int(str_ans[i])
                        low_digit_num = low_nine_num
                    elif int(str_ans[i]) - int(str_ans[i + 1]) != 0 and int(str_ans[i]) - int(str_ans[i + 1]) != 1:
                        chenged_top_num = int(str_ans[i])
                        low_digit_num = len_ans - i - 1
#                         print("AA", int(str_ans[i]), low_digit_num)
                        break
            temp_str_ans = str_ans[:len_ans - low_digit_num - 1] # not chenged
            temp_str_ans += str(chenged_top_num + 1)
            for i in range(low_digit_num):
                temp_str_ans += str(max(chenged_top_num - i, 0))
            str_ans = temp_str_ans
        
        counter += 1
#         print(counter, str_ans)
    
    print(int(str_ans))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from collections import deque
K = int(input())
queue = [str(i) for i in range(1, 10)]
# print(queue)
queue = deque(queue)
L = []
while queue:
    v = queue.popleft()
    # L.push(int(v))
    L.append(int(v))
    if v[-1] == "0":
        # print("v =", v)
        queue.append(v + v[-1])
        queue.append(v+"1")
        
    elif v[-1] == "9":
        # print("9", v)
        queue.append(v + "8")
        queue.append(v + v[-1])
    else:
        # print("else", v)
        t = int(v[-1])
        queue.append(v+str(t-1))
        queue.append(v+str(t+1))
        queue.append(v + v[-1])
    if len(L) >= K + 300:
        break
L.sort()
print(L[K-1])

Submission status: Wrong Answer

Solution code:
from collections import deque

K = int(input())

tree = deque([[0, i] for i in range(1, 10)])
i = 0
cnt = 9

while cnt <= K:
    n = tree[i][1]
    if n > 0:
        tree.append([i, n - 1])
        cnt += 1
    tree.append([i, n])
    cnt += 1
    if n < 9:
        tree.append([i, n + 1])
        cnt += 1
    i += 1

ans = ""
j = K - 1

while True:
    j, b = tree[j]
    ans = str(b) + ans
    if j == 0:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

def asym(bdict):
    pdict = {}
    pdict[0] = bdict[1]
    pdict[1] = bdict[0] + bdict[1] + bdict[2]
    pdict[2] = bdict[1] + bdict[2] + bdict[3]
    pdict[3] = bdict[2] + bdict[3] + bdict[4]
    pdict[4] = bdict[3] + bdict[4] + bdict[5]
    pdict[5] = bdict[4] + bdict[5] + bdict[6]
    pdict[6] = bdict[5] + bdict[6] + bdict[7]
    pdict[7] = bdict[6] + bdict[7] + bdict[8]
    pdict[8] = bdict[7] + bdict[8] + bdict[9]
    pdict[9] = bdict[8] + bdict[9]
    return pdict
    
if N <= 9:
    print(N)
else:
    bdict = {0:0, 1:1, 2:1, 3:1, 4:1, 5:1, 6:1, 7:1, 8:1, 9:1}
    cnt = 0
    n = 1
    while True:
        values = list(bdict.values())
        pcnt = cnt + sum(values)
        if N <= pcnt:
            ind = N - cnt  #n桁のルンルン数のうちind番目の数を求めれば良い
            cnt2 = 0
            ind2 = 0
            while True:
                esd = sum(values[:cnt2+1])
                if esd >= ind:
                    ind2 = ind - sum(values[:cnt2]) #一の位がcnt2であり、かつ桁数がnであるもののうち、ind２番目の数を求めれば良い
                    break
                else:
                    cnt2 += 1
                    
            break
                    
        else:
            cnt += sum(values)
            bdict = asym(bdict)
            n += 1
        
    alist = [str(cnt2)]
    
    def bous(alist):
        if len(alist[0]) == n:
            return alist
        else:
            blist = []
            for num in alist:
                top = int(num[0])
                plu, just, minu = top+1, top, top-1
                if plu < 10:
                    blist.append(str(plu)+num)
                if minu >= 0:
                    blist.append(str(minu)+num)
                blist.append(str(just)+num)
                alist = blist
            return(bous(alist))
        
    anc = bous(alist)
    blist = []
    for num in anc:
        if num[0] != "0":
            blist.append(int(num))
            
    blist.sort()
    print(blist[ind2-1])

Submission status: Wrong Answer

Solution code:
K=int(input())
if K<=12:
    print (K)
def digit(N):
    n=N
    lista=[]
    while n>0:
        lista.append(n%10)
        n=n//10
    return (lista)
def lunlun(x):
    for i in range(100000000):
        try:
            if abs(digit(x)[i+1]-digit(x)[i])>1:
                return ([0,i])
                break
        except IndexError:
            return ([1])
            break
t=12
X=13
lists=[1,2,3,4,5,6,7,8,9,10,11,12]
if K>12:
    while t!=K:
        if lunlun(X)[0]==1:
            lists.append(X)
            t=t+1
            X=X+1
        else:
            X=X+10**lunlun(X)[1]*1
    print (lists[K-1])

Submission status: Wrong Answer

Solution code:
from collections import deque
k = int(input())
que = deque(["1","2","3","4","5","6","7","8","9"])
c = 0
flag = True
visited = set()
res=[]
if k<=9:
    print(que[k])
else:
    while flag and len(que)!=0:
        n = len(que)
        for i in range(n):
            temp = que.popleft()
            res.append(temp)
            visited.add(temp)
            c+=1
            if int(int(temp[-1])-1)>=0:
                pot1 = str(temp) + str(int(int(temp[-1])-1))
                if pot1 not in visited:
                    que.append(pot1)
                    visited.add(pot1)
            pot2 = str(temp)+ str(temp[-1])
            
            if pot2 not in visited:
                que.append(pot2)
                visited.add(pot1)
            if int(temp[-1])==9:
                pass
            else:
                pot3 = temp+str(int(temp[-1])+1)
                if pot3 not in visited:
                    que.append(pot3)
                    visited.add(pot1)
            if c==k:
                flag = False
                break
    print(int(res[-1])%(10**9+7))

Submission status: Wrong Answer

Solution code:
K = int(input())
if K <= 9:
  print(K)
elif K <= 35:
  K = K-10
  devided = int(K/3)
  modd = K%3
  ans1 = devided+1
  ans2 = devided+modd
  answer = str(ans1)+str(ans2)
  print(answer)
K = K-35
tmp = 0
n = 100
while True:
  n = str(n)
  while True:
    k = 1
    n = str(n)
    if not (abs(int(n[k])-int(n[k+1])) <= 1 and (abs(int(n[k])-int(n[k-1])))):
      n = int(n)
      n += 1
      break
    else:
      n = int(n)
      tmp += 1
      n += 1 
  if tmp == K:
    print(n)
    break

Submission status: Wrong Answer

Solution code:
import math

K=int(input())
a=10
rr=10
if K<10:
  print(K)
else:
  while K>rr:
    if (a//10)%10-a%10==-1:
      a+=9
    else:
      a+=1
    rr+=1
        

  print(a)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
num = int(readline().rstrip())
def isRunrun(s):
    for i in range(len(s)-1):
        if (int(s[i]) - int(s[i+1])) > 1:
            return False
    return True
cnt = 0
i = 0
while cnt < num:
    i+=1
    if isRunrun(str(i)) == True:
        cnt +=1
print(i)

Submission status: Wrong Answer

Solution code:
k = int(input())

numset = {i for i in range(1,10)}
flag = False
count = len(numset)
if count >= k:
    flag = True
arr = [numset]
index = 0

while not flag:
    beforeset = arr[index]
    tmpset = set()
    for i in beforeset:
        tail = str(i)[-1]
        if tail == "0":
            tmpset.add(int(str(i)+str(0)))
            tmpset.add(int(str(i)+str(1)))
        elif tail == "9":
            tmpset.add(int(str(i)+str(8)))
            tmpset.add(int(str(i)+str(9)))
        else:
            tmpset.add(int(str(i)+str(int(tail))))
            tmpset.add(int(str(i)+str(int(tail)+1)))
            tmpset.add(int(str(i)+str(int(tail)-1)))
    count += len(tmpset)
    if count >= k:
        flag = True
    arr.append(tmpset)
    index += 1
    
totalarr = []
for tmpset in arr:
    totalarr += list(tmpset)
    
totalarr.sort()
print(totalarr[k])

Submission status: Wrong Answer

Solution code:
import sys
K=int(input())
dic={}
counts=[9]
for i in range(10):
    dic.update({(i,1):1})
tot=9
if K<=10:
    print(K)
    sys.exit()
for k in range(2,100):
    count=0
    aa=dic[(0,k-1)]+dic[(1,k-1)]
    dic.update({(0,k):aa})
    for i in range(1,10):
        cands=[i]
        if i>=1 and i<9:
            cands.append(i+1)
        if i<=9:
            cands.append(i-1)
        #print(i,cands)
        aa=0
        for each in cands:
            aa+=dic[(each,k-1)]
        dic.update({(i,k):aa})
        count+=aa
    counts.append(count)
    tot+=count
    if count >=K:
        keta=k
        print(keta)
        break
ans=counts[keta-2]
num=""
ansk=keta
for j in range(keta+1):
    for i in range(1,10):
        #print(i,keta)
        ans+=dic[(i,keta)]
        if ans>K:
            num+=str(i-1)
            if len(num)==ansk:
                print(num)
                sys.exit()

Submission status: Wrong Answer

Solution code:
K = int(input())

str_runrun = "1"

for i in range(K-1):
    str_next_runrun = str_runrun
    # 次のルンルン数を作る。ただし、未定の桁は"x"にしておく。
    for j in range(1, len(str_runrun)+1):
        if j < len(str_runrun):
            if abs(int(str_runrun[-(j+1)]) - (int(str_runrun[-j])+1)) <= 1:
                str_next_runrun = str_runrun[:-j] + str(int(str_runrun[-j])+1) + "x"*max((j-1),0)
                break
            else:
                pass
        elif str_runrun[0] != "9":
            str_next_runrun = str(int(str_runrun[0])+1) + "x"*(len(str_runrun)-1)
        else:
            str_next_runrun = "1" + "x"*len(str_runrun)
    # "x"にしておいた未定の桁を埋める。
    str_next_runrun_no_x_list = []
    for l in str_next_runrun:
        if l != "x":
            str_next_runrun_no_x_list.append(l)
        else:
            str_next_runrun_no_x_list.append(str(max(int(str_next_runrun_no_x_list[-1])-1, 0)))
    str_runrun = "".join(str_next_runrun_no_x_list)

print(str_runrun)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
def solve(K):
    d = defaultdict(list)

    d[0] = ["00", "01", "10", "11", "12"]
    d[1] = ["00", "01", "10", "11", "12", "21", "22", "23"]
    d[2] = ["10", "11", "12", "21", "22", "23", "32", "33", "34"]
    d[3] = ["21", "22", "23", "32", "33", "34", "43", "44", "45"]
    d[4] = ["32", "33", "34", "43", "44", "45", "54", "55", "56"]
    d[5] = ["43", "44", "45", "54", "55", "56", "65", "66", "67"]
    d[6] = ["54", "55", "56", "65", "66", "67", "76", "77", "78"]
    d[7] = ["65", "66", "67", "76", "77", "78", "87", "88", "89"]
    d[8] = ["76", "77", "78", "87", "88", "89", "98", "99"]
    d[9] = ["87", "88", "89", "98", "99"]

    initial = [0, 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]
    if K < len(initial):
        print(initial[K])
        return

    counter = len(initial)
    while True:
        new_adj = defaultdict(list)
        for i in range(0, 10):
            for j in d[i]:  # 最初の文字がiのとき
                n = (str(i)+j)
                if(n[0]!="0"):
                    counter += 1
                if counter == K+1:
                    print("---------")
                    print(n)
                    print("---------")
                    return

                new_adj[i].append(n)
                if i != 0:
                    new_adj[i-1].append(n)
                if i != 9:
                    new_adj[i+1].append(n)

        d = new_adj
K = int(input())
solve(K)
#solve(100000)
#print(3234566667)

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())

flag=True
count=0
for i in range(10**5):
    j=str(i)
    arr = list(map(int, j))

    for k in range(len(arr)-1):
        if abs(arr[k]-arr[k+1]) > 1:
            break
        else:
            count+=1

    if count==K-9:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
import sys
def bstr(s):
  return (str(s))[-1]
def check(n):
  if n<13:
    return True
  s=str(n)
  for i in range(len(s)-1):
    if(-2<(int(s[i])-int(s[i+1]))<2):
      pass
    else:
      return False
  return True

def solve(m):
  for i in range(len(str(m))):
    p=0
    r=0
    t=0
    if i==1:
      p = 1
    if i==2:
      p = 13
      r = 12
      t = 11
    if i>2:
      p=int("".join(list(map(bstr,list(range(1,(i-1),2))))))
      r=int("".join(list(map(bstr,list(range(1,(i-1),1))))))
      t=int("".join(list(map(str,([1]*i)))))
    n=m+pow(10,i) 
    if check(n-p):
      return (n-p)
    if check(n-r):
      return (n-r)
    if check(n-t):
      return (n-t)
    n=m+pow(10,i)
    if check(n):
      return n

k=int(input())
if k <13:
  print(k)
  sys.exit()
q = 12
for i in range(k-12):
  q = solve(q)
print(q)

Submission status: Wrong Answer

Solution code:
K=int(input())
number_list=[i for i in range(1,10**5 +1)]
cnt=0
for i in number_list:
    if i<=9:
        cnt += 1
        if cnt == K:
            print(i)
            exit()
    else:
        ln=[int(j) for j in str(i)]
        op=[]
        for k in range(len(ln)-1):
            op.append(abs(ln[k+1]-ln[k]))
            if set(op) == {0} or {1} or {0,1} :
                cnt+=1
                op.clear()
                if cnt == K:
                    print(i)
                    exit()
            else:
                op.clear()

Submission status: Wrong Answer

Solution code:
import math

K=int(input())
a=10
rr=10
if K<10:
  print(K)
else:
  while K>rr:
    if a//10-a%10==-1:
      a+=9
    else:
      a+=1
    rr+=1
        

  print(a)

Submission status: Wrong Answer

Solution code:
K = int(input())
N = 1000

dp = [[0 for _ in range(10)] for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(10):
        if i == 0:
            dp[i][j] = 1
        else:
            if j == 9:
                dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j]
            elif j == 0:
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j + 1]
            else:
                dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1]


def get_i2_j2_sum2():
    sum1 = 0
    for i in range(N):
        for j in range(1, 10):
            sum1 += dp[i][j]
            if sum1 >= K:
                i2 = i
                j2 = j
                sum2 = sum1
                # print(i, j, sum1)
                return i2, j2, sum2


i2, j2, sum2 = get_i2_j2_sum2()
print(i2, j2, sum2)


def get_j(i_input, j_input, sum2):
    for j in [j_input + 1, j_input, j_input - 1]:
        if j < 0 or 9 < j:
            continue
        sum2 -= dp[i_input][j]
        print('###', i_input, j, sum2)
        if sum2 < K:
            return j, sum2
    raise Exception


ans = [j2]
for i in range(i2 - 1, -1, -1):
    j2, sum2 = get_j(i, j2, sum2)
    ans.append(j2)
    # print(i, j2)

print(''.join([str(s) for s in ans]))

Submission status: Wrong Answer

Solution code:
k = int(input())

i = 0
n = 0
flg = 0
while True:
  i += 1
  s = str(i)
  for j in range(len(s)-1):
    if (int(s[j]) - int(s[j+1])) not in [-1, 0, 1]:
      if flg == 0:
        i += 8 * (10**(len(s)-j-1)) - 1
        flg = 1
      break
  else:
    n += 1
    flg=0
    if n == k:
      print(i)
      break

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())

flag=True
count=0
for i in range(10**5):
    j=str(i)
    arr = list(map(int, j))

    for k in range(len(arr)-1):
        if abs(arr[k]-arr[k+1]) > 1:
            break
        else:
            print(arr)
            count+=1

    if count==K-9:
        print(i)
        exit()

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    K = II()
    if K <= 10:
            print(K)
            return
    x = [0]
    x = [0,1]
    for _ in range(K-10):
        # print(x)
        c = 1
        for j in range(len(x)):
            if c == 0:
                break
            x[j] += 1
            c = x[j] // 10
            x[j] %= 10
        if c == 1:
            x.append(1)


        for i in range(1,len(x)):
            d = x[i] - x[i-1]
            if d < -1:
                c = 1
                for j in range(i,len(x)):
                    if c == 0:
                        break
                    x[j] += 1
                    c = x[j] // 10
                    x[j] %= 10
                if c == 1:
                    x.append(1)
                for j in range(i,0,-1):
                    x[j-1] = max(x[j] - 1,0)
            elif d > 1:
                x[i-1] = x[i] - 1

    
    ans = 0
    # print(x)
    for i in x[::-1]:
        ans *= 10
        ans += i
    print(ans)
    

    
    

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
K = int(input())

lis = [[0]*12 for _ in range(10)]
lis[9] = [0,3,3,3,3,3,3,3,3,3,2,0]
for i in range(8,-1,-1):
  for j in range(1,11):
    lis[i][j] = lis[i+1][j-1] + lis[i+1][j] + lis[i+1][j+1]

new_lis = [[0]*10 for _ in range(10)]
new_lis[9] = [9,3,3,3,3,3,3,3,3,2]
for i in range(8,-1,-1):
  for j in range(10):
    if j == 0:
      new_lis[i][j] = sum(new_lis[i+1])
    else:
      new_lis[i][j] = lis[i][j]
      
ans = 0
cnt = 0
for i in range(10):
  if ans == 0:
    s,e = 0,9
  else:
    s = max(0,j-1)
    e = min(9,j+1)
  for j in range(s,e+1):
    #print('cnt',cnt)
    if cnt + lis[i][j] >= K:
      #print('ij',cnt,i,j)
      break
    cnt += lis[i][j]
  #print(ans,j)
  ans += j*10**(10-i)
  #print(ans)
#print(K-cnt,j)
ans += K-cnt+j-2
  

#print(new_lis)
print(ans)
#print(*ans,sep=' ')

Submission status: Wrong Answer

Solution code:
#200404D
import math
K = int(input())
count = 0
X = int(0)
while count < K:
    X +=1
    L = len(str(X))
    #print(L)
    flag = 1
    if L ==1:
        count +=1
    else:
        for i in range(L-1):
            num = []
            #print(X)
            Y = X
            for i in range(L):
                num.append(Y % 10)
                Y = math.floor(Y//10)
                #print('A')
            #print(num)
            #print(num[0]) 
            #print(num[1])
            #print('B')

            if abs(num[i-1]//1-num[i])<=1:
                #print(num[i-1]//1)
                #print(num[i])
                continue
                
            else:
                flag = 0
                break

        if flag ==1:
            count += 1
            #print(X)
print(X)

Submission status: Wrong Answer

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

K = ni()
if K <=9: 
    print(K)

u = []
dp = [[1] * 10,] 
sum = 0
for j in range(1,10):
    sum += dp[0][j]
# print(sum)
u.append(sum)
for i in range(1,10):
    a = dp[i-1]
    b = [a[0]+a[1],]
    for j in range(1,9):
        b.append(a[j-1]+a[j]+a[j+1])
    b. append(a[8]+a[9])
    dp.append(b)
    # print(dp)
    for j in range(1,10):
        sum += dp[i][j]
    # print(sum)
    u.append(sum)
# print(u)

def ggg(upN,keta,n):
    # print("ggg",upN,keta,n)
    s = 0
    start = max(upN-1,0)
    end = min(upN+ 1,9)
    for i in range(start, end+1):
        #print("keta",keta,start,"N",n,s,dp[keta -1][i])
        if n <= s + dp[keta -1][i]:
            #print("debug")
            if keta == 1:
                    # print("deb2")
                    return i
            else:
                return i * 10 **(keta -1) + ggg(i,keta-1,n -s)
        s += dp[keta-1][i]
        #print("xxx",i,s)
    print("Erorr ggg",upN,keta,n)
    exit(-1)

def fff (keta,n):
    #print("fff",keta,n)
    s = 0
    for i in range(1,10):
        if n <= s + dp[keta-1][i]:
            return i * 10 ** (keta-1) + ggg(i,keta-1,n-s)
        s += dp[keta-1][i]
    print("Error")
    exit(-1)


for i in range(1,10):
    if K <= u[i]:
        print(fff(i+1,K-u[i-1]))
        exit(0)

Submission status: Wrong Answer

Solution code:
k = int(input())
ans1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ite = 9

if (k < 10):
    print(ans1[k - 1])
elif (k == 100000):
    print(3234566667)
else:
    while (ite < k):
        ans2 = []
        for num in ans1:
            keta1 = num % 10
            if (keta1 == 0):
                ans2.append(num * 10)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + 1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + 9)
                ite += 1
                if (ite == k):
                    break
            elif (keta1 == 9):
                ans2.append(num * 10)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1 - 1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1)
                ite += 1
                if (ite == k):
                    break
            else:
                ans2.append(num * 10 + keta1 - 1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1)
                ite += 1
                if (ite == k):
                    break
                ans2.append(num * 10 + keta1 + 1)
                ite += 1
                if (ite == k):
                    break
        ans1 = ans2[:]
    print(ans2[-1])

Submission status: Wrong Answer

Solution code:
K = int(input())

if K < 13:
  print(K)
else:
  # N = list(range(1,10))
  c = 9
  l = 2
  n = 1
  while c < K:
    for j in range(3):
      if n > 9: n = 1
      a = str(n)
      for i in range(l-1):
        if j == 0: 
          a += str(n-1)
        elif j == 1:
          a += str(n)
        else:
          a += str(n+1)
      # N.append(a)
      c += 1
    n += 1
    if a == "9" * l: l += 1
  print(a)

Submission status: Wrong Answer

Solution code:
K = int(input())
count = 0
lunlun = 0

while count < K:
  #  count =+ 1
  #print(lunlun)
  ketasu = len(str(lunlun))
  lunlun = lunlun + 1
  flag = 0
  if ketasu == 1:
    count = count + 1
  else:
    for i in range(1, ketasu):
      # print((lunlun%(10**(i+1))//(10**i)), (lunlun%(10**i)))
      if abs((lunlun%(10**(i+1))//(10**i))-(lunlun%(10**i))) > 1:
        batsuketa = i
        break
      flag = flag + 1
    if flag == ketasu-1:
      print(lunlun)
      count = count + 1
    elif ((lunlun%(10**(i+1))//(10**i))-(lunlun%(10**i))) > 1:

      lunlun = (lunlun+10**batsuketa) // (10**batsuketa) * (10**batsuketa)

print(lunlun)

Submission status: Wrong Answer

Solution code:
from collections import deque
hash={1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,10:10}
k=int(input())
cnt=10
flag=True
if k<=10:
    print(k)
    exit()
tmp=11
while(flag):
    numstr=list(str(tmp))
    if len(numstr)<=2:
        lun=0
        for i in reversed(range(len(numstr)-1)):
            if abs(int(numstr[i])-int(numstr[i+1]))<=1:
                lun+=1
            else:
                break
        if lun==(len(numstr)-1):
            cnt+=1
            hash[tmp]=cnt
        if cnt==k:
            print(tmp)
            break
        else:
            tmp+=1
    else:
        for i in range(0,len(numstr)-1):
            tmp2=[]
            tmp2.append(numstr[i])
            tmpint="".join(tmp2)
        if int(tmpint) in hash:
            for j in range(1,len(numstr)):
                tmp3=[]
                tmp3.append(numstr[j])
                tmpint2="".join(tmp3)
            if int(tmpint2) in hash:
                cnt+=1
                hash[tmp]=cnt
        if cnt==k:
            print(tmp)
            break
        else:
            tmp+=1