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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
#![allow(unused_mut)]
#![allow(bare_trait_objects)]
#![allow(unused_imports)]
#![allow(unused_macros)]
// #![allow(dead_code)]

// https://github.com/tanzaku/rust-procon-lib
#[macro_use]
extern crate rust_procon_lib;

use rust_procon_lib::modcomb::*;
use rust_procon_lib::modint::*;
use rust_procon_lib::scanner::*;
use rust_procon_lib::tree::*;

// make_modint!(MOD_1000000007);
// make_modcomb!();

// fn dfs(memo: &mut Vec<Vec<usize>>, k: usize, prev: usize) -> usize {
//     // eprintln!("1 {} {} {}", k, prev, memo[k][prev]);
//     if memo[k][prev] == std::usize::MAX {
//         let mut ans = 0;
//         if prev > 0 {
//             ans += dfs(memo, k, prev - 1);
//         }
//         for i in 0..10 {
//             if (i as i64 - prev as i64).abs() <= 1 {
//                 // eprintln!("2 {} {}", k, prev);
//                 ans += dfs(memo, k - 1, i);
//             }
//         }
//         memo[k][prev] = ans;
//     }
//     memo[k][prev]
// }

fn dfs(ans: &mut Vec<i64>, k: usize, v: i64, prev: i64) {
    if k == 0 {
        ans.push(v);
        return;
    }
    for i in 0..10 {
        if (i as i64 - prev as i64).abs() <= 1 {
            dfs(ans, k - 1, v * 10 + i, i)
        }
    }
}

fn main() {
    let mut sc = Scanner::from_stdin();

    let mut k = sc.usize();

    // let mut memo = vec![vec![std::usize::MAX; 10]; 20];
    // for i in 0..10 {
    //     memo[0][i] = i;
    // }

    // let mut last = 0;
    // let mut ans = 0;
    // for i in (0..13).rev() {
    //     let mut val = std::cmp::max(last, 1) - 1;
    //     for j in (1..=9).rev() {
    //         if ans != 0 && (last as i64 - (j + 1) as i64).abs() > 1 {
    //             continue;
    //         }

    //         if k >= dfs(&mut memo, i, j) {
    //             eprintln!("{} {} {}", j, k, dfs(&mut memo, i, j));
    //             k -= dfs(&mut memo, i, j);
    //             val = j;
    //             break;
    //         }
    //     }
    //     last = val;
    //     ans += 10_i64.pow(i as u32) * last as i64;
    // }
    // println!("{}", ans);

    let mut ans = Vec::new();
    for i in 0.. {
        if ans.len() >= k {
            break;
        }
        for j in 1..10 {
            dfs(&mut ans, i, j, j)
        }
    }
    println!("{}", ans[k - 1]);
}
*/

fn main() {
    let exe = "/tmp/bin3D02F2A8";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";