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++ (GCC 5.4.1) (judge verdict: Runtime Error)

#include<bits/stdc++.h>
using namespace std;
vector<long long> v;
int main(){
	int x;
	cin>>x;
	for(long long a=1;a<=9;a++){
		v.push_back(a);
		for(long long b=a-(a>0);b<=a+(a!=9);b++){
			v.push_back(a*10+b);
			for(long long c=b-(b>0);c<=b+(b!=9);c++){
				v.push_back(a*100+b*10+c);
				for(long long d=c-(c>0);d<=c+(c!=9);d++){
					v.push_back(a*1000+b*100+c*10+d);
					for(long long e=e-(d>0);e<=d+(d!=9);e++){
						v.push_back(a*10000+b*1000+c*100+d*10+e);
						for(long long f=e-(e!=0);f<=e+(e!=9);f++){
							v.push_back(a*100000+b*10000+c*1000+d*100+e*10+f);
							for(long long g=f-(f!=0);g<=f+(f!=9);g++){
								v.push_back(a*1000000+b*100000+c*10000+d*1000+e*100+f*10+g);
								for(long long h=g-(g!=0);h<=g+(g!=9);h++){
									v.push_back(a*10000000+b*1000000+c*100000+d*10000+e*1000+f*100+g*10+h);
									for(long long i=h-(h!=0);i<=h+(h!=9);i++){
										v.push_back(a*100000000+b*10000000+c*1000000+d*100000+e*10000+f*1000+g*100+h*10+i);
										for(long long j=i-(i!=0);j<=i+(i!=9);j++){
											v.push_back(a*1000000000+b*100000000+c*10000000+d*1000000+e*100000+f*10000+g*1000+h*100+i*10+j);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	sort(v.begin(),v.end());
	/*for(int i=0;i<1000;i++){
		cout<<i<<' '<<v[i]<<'\n';
	}*/
	cout<<v[x-1]<<'\n';
}