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: Runtime Error)

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int num = 9 * 14 * 15 / 2;
        String[] list = new String[num];
        long[] ll = new long[num];
        int[] div = new int[num];
        ArrayList<String> snuke = new ArrayList<String>();
        int c = 0;
        for (int i = 0; i < 15; i++) {
            for (int l = 1; l < 10; l++) {
                for (int j = 0; j < i; j++) {
                    String tmp = l + "";
                    for (int m = j; m < i-1; m++) {
                        tmp = tmp + "0";
                    }
                    for (int m = 0; m < j; m++) {
                        tmp = tmp + "9";
                    }
                    list[c] = tmp;
                    ll[c] = Long.parseLong(tmp);
                    for(int m=0; m<tmp.length(); m++){
                        div[c] += Integer.parseInt(String.valueOf(tmp.charAt(m)));
                    }
                    c++;
                }
            }
        }
        double min = Double.MAX_VALUE;
        for(int i=0; i<num; i++){
            int p = num - i - 1;
            double tmp = (double)(ll[p]) / (double)(div[p]);
            if(tmp < min + 0.000000001d){
                min = tmp;
                snuke.add(list[p]);
            }
        }
        Collections.reverse(snuke);
        for(int i=0; i<k; i++){
            System.out.println(snuke.get(i));
        }
    }
}