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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class MainApp
{

	static public void Main()
	{

		int K = Oneint();
		int[] k = new int[K];
		string ans = "";
		int num = 0;
		int A = 0;

		if (K < 10)
		{
			Console.WriteLine(K);
		}
      	else if(K < 11){
        	Console.WriteLine(10);
        }
		else
		{
			A = 1;      //基準
			k[0] = -1;	//1桁目
			num = 1;    //機能している桁
			for(int j = 11; j < K+1; j++)
			{
				int ok = 0;
				while(ok == 0)
				{
					k[0]++;							//数字を一つ増やす
					
					for (int i = 0; i < num-1; i++)
					{
                      
						if (k[i] == 2)              //2になったら
						{
							k[i] = -1;
							k[i + 1]++;
						}
						else
						{
							i = num;
						}
					}
					if (k[num - 1] == 2)                //基準の一つ下が2になったら
					{
						A++;                        //Aの値を1増やす
						k[num - 1] = -1;             
						
						if (A == 10)                        //桁が変わったら
						{
							num++;                      //機能桁をふやして
							k[num - 1] = -1;            //一番上の機能桁を-1にして
							A = 1;                      //Aを1にする
						}
					}
	
					 


					int ifnum = A;
                  
					for (int i = 0; i < num; i++)       //その数字が数字として成立するか否か
					{
						ifnum += k[num - i - 1];
                      
						if (ifnum < 0 || ifnum > 9)              //もし数字として成立しなかったら
						{
							i = num;                //ループを出る
						}
						else
						{
							if(i == num - 1)
							{
								ok = 1;
                              //Console.WriteLine(ifnum);
							}
                          
						}
					}
				}
			}
			int ifif = A;         
            ans = ifif.ToString();
			for(int i = 0; i < num; i++)
			{
				ifif += k[num - i -1];
				ans += ifif.ToString();
              //Console.WriteLine(k[num - i -1]);
			}
			Console.WriteLine(ans);
			
		}



	}


	private static string[] Arraystring()
	{
		return Console.ReadLine().Split(' ');
	}

	private static string Onestring()
	{
		return Console.ReadLine();
	}

	private static int Oneint()
	{
		return int.Parse(Console.ReadLine());
	}

	private static int[] Arrayint()
	{
		return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
	}
}