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)

#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn digit_sum(n: i64) -> i64 {
    if n == 0 {
        return 0;
    }
    else {
        return n % 10 + digit_sum(n/10);
    }
}

fn gen(n: i64, m: i64) -> i64 {
    if m == 0 {
        return n;
    }
    else {
        return gen(n * 10 + 9, m-1);
    }
}

fn main() {
    let inf = 1i64 << 62;
    let mut count = 0;
    let k = read_i64();
    let mut res = vec![];
    for i in 1..9+1 {
        res.push(i);
    }
    for i in 1..9+1 {
        res.push(gen(i,1));
    }
    for d in 3..16 {
        for i in 100..1000 {
            let n = gen(i, d-3);
            let mut p = 1;
            let mut ok = true;
            for _ in 0..17 {
                let mut m = n + p;
                if ! (n * digit_sum(m) <= m * digit_sum(n)) {
                    ok = false;
                }
                p *= 10;
            }
            if ok {
                if res.len() >= k as usize {
                    break;
                }
                res.push(n);
            }
        }
    }
    for i in 0..k {
        println!("{}", res[i as usize]);
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}