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::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn s(n: i64) -> i64 {
    let mut sum = 0;
    let mut nn = n;
    while nn >= 1 {
        sum += nn % 10;
        nn /= 10
    }
    sum
}

const MAX: i64 = 1e15 as i64;

fn generate_snuke() -> Vec<(i64, i64)> {
    let mut candidate_snuke = vec![];
    let mut pow10 = 1;

    for _ in 1..15 {
        for i in 1..100000 {
            let n = i * pow10 - 1;
            if n > MAX {
                break;
            }
            if n >= 1 {
                candidate_snuke.push((n, s(n)));
            }
        }
        pow10 *= 10;
    }
    candidate_snuke
}

fn compare((a, sa): (i64, i64), (b, sb): (i64, i64)) -> Ordering {
    if a * sb < b * sa {
        Ordering::Less
    } else if a * sb > b * sa {
        Ordering::Greater
    } else {
        Ordering::Equal
    }
}

fn main() {
    let mut k: i32 = read();
    let mut snuke = generate_snuke();
    snuke.sort_by(|&a, &b| compare(a, b));
    let mut max = 0;
    for &(a, s) in snuke.iter().by_ref() {
        if max < a {
            max = a;
            println!("{}", max);
            k -= 1;
            if k == 0 {
                break;
            }
            // println!("{} -> {} ({})", max, s, max as f64 / s as f64);
        }
    }
}