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.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var K = Sarray()[0];
            var Calc = 13;

            var dp = new long[10,Calc][];//左端が1、桁数、num
            for (var i = 0; i < 10; ++i)
                for (var j = 0; j < Calc; ++j)
                    dp[i, j] = new long[10];
            for (var l = 0; l <= 9; ++l)
            {
                dp[l, 1][l] = 1;
                for (var i = 2; i < Calc; ++i)
                {
                    dp[l, i][0] = dp[l, i - 1][0] + dp[l, i - 1][1];
                    for (var j = 1; j < 9; ++j)
                        dp[l, i][j] = dp[l, i - 1][j - 1] + dp[l, i - 1][j] + dp[l, i - 1][j + 1];
                    dp[l, i][9] = dp[l, i - 1][8] + dp[l, i - 1][9];
                }
            }
            var rui = 0L;
            var keta = 0L;
            var ban = 0L;
            var top = 0L;
            var flg = false;
            var ans = new List<long>();
            for (var k = 1; k < Calc; ++k)
            {
                for (var l = 1; l <= 9; ++l)
                {
                    ban = rui;
                    rui = rui + dp[l, k].Sum();
                    if (K <= rui)
                    {
                        ban = K - ban;
                        keta = k;
                        top = l;
                        flg = true;
                        ans.Add(top);
                    }
                    if (flg) break;
                }
                if (flg) break;
            }
            //ketaの小さい方からban番目
            //WriteLine($"{keta}桁で頭が{top}の{ban}番目");
            while (1 != keta)
            {
                var next = ban;
                rui = 0L;
                --keta;
                for (var l = Max(0, top - 1); l <= Min(9, top + 1); ++l)
                {
                    ban = rui;
                    rui = rui + dp[l, keta].Sum();
                    if (next <= rui)
                    {
                        ban = next - ban;
                        top = l;
                        ans.Add(top);
                        break;
                    }
                }
                //WriteLine($"{keta}桁で頭が{top}の{ban}番目");
            }
            WriteLine(string.Join("", ans));
            //Out.Flush();
        }
    }
}