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.42.0) (judge verdict: Wrong Answer)

// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use libm::*;
use std::cmp::*;
use std::collections::BinaryHeap;
use std::io::*;
use std::str::FromStr;
use superslice::*;

pub 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")
}

//abc161-D
// #[fastout]
fn main() {
    input![n: usize];

    let mut is_rnrn = vec![false; 1000000];

    let mut count = 0;
    is_rnrn[0] = true;
    for i in 1..10 {
        count += 1;
        eprintln!("{}'s rnrn: {}", count, i);
        if n == count {
            println!("{}", i);
            return;
        }
        is_rnrn[i] = true;
    }

    for i in 10..(1000000) {
        let d = log10(i as f64) as u32;
        let a = 10i64.pow(d);
        let max_d = i as i64 / a as i64;
        let no2_d = i as i64 / (10i64.pow(d - 1)) % 10 as i64;
        let rest_digits = i - max_d * a;
        // eprintln!("{}, {}, {}, {}", i, max_d, no2_d, rest_digits);
        if !is_rnrn[rest_digits as usize] {
            is_rnrn[i as usize] = false;
        } else if fabs((max_d - no2_d) as f64) as usize <= 1 {
            count += 1;
            eprintln!("{}'s rnrn: {}", count, i);
            if n == count {
                println!("{}", i);
                break;
            }
            is_rnrn[i as usize] = true;
        } else {
            is_rnrn[i as usize] = false;
        }
    }
}

fn go(mid: usize, d: usize, use_num: usize, num753_cand: &mut Vec<usize>, n: usize) {}

// use lazy_static::lazy_static;
// use std::sync::Mutex;

// lazy_static! {
//     static ref VALUES: Mutex<Vec<i32>> = Mutex::default();
// }

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);