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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.io.*;
import java.util.*;

public class Main {

    static int K;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        K = sc.nextInt();

        PrintWriter pw = new PrintWriter(System.out);
        for (long l : solve()) {
            pw.println(l);
        }
        pw.flush();
    }

    static long[] solve() {
        List<Snuke> candidates = new ArrayList<>();

        for (int i = 1; i <= 9; i++) {
            candidates.add(new Snuke(i));
        }

        for (int i = 1; i <= 99; i++) {
            for (int j = 1; j < 13 ; j++) {
                long v = Long.parseLong(i + nines(j));
                candidates.add(new Snuke(v));
            }
        }
        candidates.sort(Comparator.comparingLong(s -> s.i));

        List<Snuke> matches = new ArrayList<>();
        loop: for (int i = 0; i < candidates.size(); i++) {
            Snuke s = candidates.get(i);
            for (int j = i+1; j < candidates.size(); j++) {
                Snuke after = candidates.get(i);
                if( s.compareTo(after) > 0 ) continue loop;
            }
            matches.add(s);
        }

        long[] ans = new long[K];
        for (int i = 0; i < K; i++) {
            ans[i] = matches.get(i).i;
        }
        return ans;
    }

    static String nines(int times) {
        char[] cs = new char[times];
        Arrays.fill(cs, '9');
        return new String(cs);
    }

    static class Snuke implements Comparable<Snuke> {
        long i;
        int p;

        public Snuke(long i) {
            this.i = i;
            this.p = toPoint(i);
        }

        @Override
        public int compareTo(Snuke o) {
            // i/p < o.i/o.p
            // -> i*o.p < o.i*p
            long a = i * o.p;
            long b = o.i * p;
            return Long.compare(a, b);
        }
    }

    static int toPoint(long value) {
        String s = String.valueOf(value);
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += s.charAt(i) - '0';
        }
        return sum;
    }

    @SuppressWarnings("unused")
    static class FastScanner {

        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}