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)

use std::collections::{HashMap, VecDeque};
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
struct Main {
    k: usize,
    a: Vec<Vec<i64>>,
}
impl Main {
    fn invoke(&mut self) {
        for i in 1..10 {
            let a = self.a[i - 1].clone();
            let mut new_a = vec![];
            for &v in a.iter() {
                let num_str = v.to_string();
                let num_chars = num_str.chars();
                let last_num = num_chars.clone().last().unwrap() as i64 - 48;
                let new_chars: Vec<char> = if last_num == 0 {
                    vec!['0', '1']
                } else if last_num == 9 {
                    vec!['8', '9']
                } else {
//                    println!("{}, {}, {}", last_num - 1, last_num, last_num + 1);
                    vec![last_num - 1, last_num, last_num + 1]
                        .iter()
                        .map(|&n| std::char::from_digit(n as u32, 10).unwrap())
                        .collect::<Vec<char>>()
                };
                for &c in new_chars.iter() {
                    let new_num_chars = num_chars.clone();
                    let mut new_num_chars_vec = new_num_chars.collect::<Vec<char>>();
                    new_num_chars_vec.push(c);
                    let mut new_num_str = "".to_string();
                    for &num_char in new_num_chars_vec.iter() {
                        new_num_str.push(num_char);
                    }
                    let new_num: i64 = new_num_str.parse().unwrap();
                    new_a.push(new_num);
                }
            }
            self.a[i] = new_a;
        }
//        println!("{:?}", self.a);
        let res = self.a.iter().flat_map(|a_one| a_one).collect::<Vec<_>>();
        println!("{}", res[self.k - 1]);
    }
}
fn main() {
    let k: usize = read();
    Main {
        k: k,
        a: vec![(1..10).collect::<Vec<i64>>(); 10],
    }
        .invoke()
}