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 Scala (2.11.7) (judge verdict: Wrong Answer)

object Main extends App {
  def sumDigit(i:Long) = {
    var temp = i
    var sum = 0
    while (temp>0){
      sum = sum + (temp%10).toInt
      temp = temp/10
    }
    sum
  }
  def log10(n:Long) = {
    var nv =n
    var count = 0
    while(nv/10>0){
      nv = nv /10
      count = count + 1
    }
    count
  }
  def pow10(i:Int) = {
    (1 to i).map(x=>10L).foldLeft(1L)((x,y)=>x*y)
  }
  def judge(n:Long) = {
    val sN = sumDigit(n)
    var base = 1
    var flag = true
    val baseMax = log10(n)
    while ((base <= baseMax) && flag){
      val mBase = pow10(base)
      val m = mBase-1-(n%mBase)
      val sM = sumDigit(m)
      if (n*sM>m*sN){
        flag = false
      }
      base = base + 1
    }
    flag
  }
  val sc = new java.util.Scanner(System.in)
  val k = sc.nextLong()
  var counter = 0L
  var current9s = 9L
  var currentPrefix = 1L
  val pw = new java.io.PrintWriter(System.out)
  while (counter < k){
    if (counter < 9){
      println(counter+1)
      counter = counter + 1
    } else {
      val current = current9s + currentPrefix * (current9s + 1)
      if (judge(current)){
        pw.println(current)
        counter = counter + 1
      }
      currentPrefix = currentPrefix + 1
      if (currentPrefix > 10){
        current9s = current9s * 10 + 9
        currentPrefix = 1
      }
    }
  }
  pw.flush()
}