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: Wrong Answer)

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long    ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second

#define fore(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
#define forr(i, b, e)    for (ll i = (ll)b; i < (ll)e; i++)
ll faster_in(){ll r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = ll(1e9 + 7);
const lldb PI = acos(-1);
#define tam 3200
const ll MOD=1e9+7;
ll dp[tam][123];
int f(int pos,int lastdig)
{
    if (lastdig<0|| lastdig>=10)
        return 0;
    if (pos==0)
        return 1;
    if (dp[pos][lastdig]!=-1)
        return dp[pos][lastdig];
    ll res=0;
    res+=f(pos-1,lastdig);
    res+=f(pos-1,lastdig+1);
    res+=f(pos-1,lastdig-1);
    dp[pos][lastdig]=res;
}

ll kth;
void print(int pos,int lastdig)
{
    if (lastdig==10)
        assert(false);
    cout<<lastdig;
    if (pos==0)
        {
            cout<<endl;
            exit(0);
            return;
        }
    if (lastdig>0 && kth<=f(pos-1,lastdig-1)){
        print(pos-1,lastdig-1);
        return;
    }
    kth-=f(pos-1,lastdig-1);
    if (kth<=f(pos-1,lastdig)|| lastdig+1==10)
    {
        print(pos-1,lastdig);
        return;
    }
    kth-=f(pos-1,lastdig);
    print(pos-1,lastdig+1);
}
int main()
{    
    memset(dp,-1,sizeof dp);
    
    cin>>kth;
    forr(digs,1,100)
    {
        forr(lastdig,1,10)
        {
            if (kth<=f(digs-1,lastdig))
            {
                print(digs-1,lastdig);
                return 0;
            }

            kth-=f(digs-1,lastdig);
        }
        //cout<<kth<<" "<<digs<<endl;
    }

}
// PLUS ULTRA!