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.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <unordered_map>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
#define out(x) cout<<x<<'\n';
inline char gc(){char op[2];scanf("%s",op);return op[0];}
const int N = 2e5+10;
const double eps = 0.00000001;
const ll mod = 3e9 ;
using namespace std;
ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
unordered_map<ll,bool> hap;
vector<ll> Q;
ll t1,t2,t3,x,tmp;
void init(){
    queue<ll> q;
    rep(i,1,9) q.push(i),Q.push_back(i);
    while(q.size()){
        x = q.front();
        q.pop();
        if(x/mod) continue;
        tmp = x % 10;
        if(tmp==0){
            t1 = x * 10;
            t2 = t1 + 1;
            if(hap.count(t1)==0) hap[t1] = 1,q.push(t1),Q.push_back(t1);
            if(hap.count(t2)==0) hap[t2] = 1, q.push(t2),Q.push_back(t2);
        }
        else if(tmp==9){
            t1 = x*10+8;
            t2 = t1 + 1;
            if(hap.count(t1)==0) hap[t1] = 1,q.push(t1),Q.push_back(t1);
            if(hap.count(t2)==0) hap[t2] = 1, q.push(t2),Q.push_back(t2);
        }
        else{
            t1 = x*10+tmp-1;
            t2 = t1 + 1;
            t3 = t2 + 1;
            if(hap.count(t1)==0) hap[t1] = 1,q.push(t1),Q.push_back(t1);
            if(hap.count(t2)==0) hap[t2] = 1, q.push(t2),Q.push_back(t2);
            if(hap.count(t3)==0) hap[t3] = 1, q.push(t3),Q.push_back(t3);
        }
    }
}
int main(){
    int k = read();
    init();
    sort(Q.begin(),Q.end());
    cout<<Q[k-1];
}