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 Go (1.6) (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var i, k int64
	fmt.Sscan(getNextLine(scanner), &k)
	var ans int64
	ans = 0
	for i = 0; i < k; i++ {
		ans = chokudai(ans + 1)
		fmt.Println(ans)
	}
}

func chokudai(j int64) int64 {
	var i, d, s, ts, temp int64
	d = 0
	s = 0
	for i = j; i > 0; i /= 10 {
		s += i % 10
		d++
	}
	min := j / s
	ans := j
	for i = 1; i < d; i++ {
		ts = 0
		temp = j
		for ii := i; ii > 0; ii-- {
			temp /= 10
		}
		temp++
		for ii := i; ii > 0; ii-- {
			temp *= 10
		}
		temp--

		for t := temp; t > 0; t /= 10 {
			ts += t % 10
		}
		if min >= temp/ts {
			min = temp / ts
			ans = temp
		}
	}
	return ans
}