Problem:
Score : 500 points

Problem Statement

Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.

We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.

Given an integer K, list the K smallest Snuke numbers.

Constraints

1 \leq K

The K-th smallest Snuke number is not greater than 10^{15}.

Input

Input is given from Standard Input in the following format:

K

Output

Print K lines. The i-th line should contain the i-th smallest Snuke number.

Sample Input 1

10

Sample Output 1

1
2
3
4
5
6
7
8
9
19

Solution in Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
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")
}

fn get_value(x: usize) -> usize {
    let mut x = x;
    let mut ret = 0;
    while x > 0 {
        ret += x % 10;
        x /= 10;
    }
    ret
}

fn main() {
    let k = read::<usize>();
    let mut sunuke = vec![];
    for i in 1..10 {
        sunuke.push(i);
        sunuke.push(i * 10 + 9);
    }
    for i in 3..16 {
        'outer_loop: for v1 in 100..1000 {
            let mut lhs = v1;
            let mut base = 1;
            for _ in 3..i {
                lhs = lhs * 10 + 9;
                base *= 10;
            }
            // println!("{}", lhs);
            let mut rhs = lhs;
            for _ in 0..2000 {
                rhs += base;
                if lhs * get_value(rhs) >= rhs * get_value(lhs) {
                    continue 'outer_loop;
                }
            }
            // println!("{}", rhs);
            // println!("{}", base);
            sunuke.push(lhs);
        }
    }
    sunuke.sort();
    sunuke.dedup();
    for i in 0..k {
        println!("{}", sunuke[i]);
    }
    // for &v in sunuke.iter() {
    //     println!("{}", v);
    // }
    // let MAX_VALUE = 10000000;
    // let mut value = vec![0; MAX_VALUE];
    // for i in 0..MAX_VALUE {
    //     value[i] = get_value(i);
    // }
    // 'outer_loop: for i in 0..1000000 {
    //     for j in i + 1..MAX_VALUE {
    //         if i * value[j] > j * value[i] {
    //             continue 'outer_loop;
    //         }
    //     }
    //     println!("{}", i);
    // }
}