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: Wrong Answer)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	snuke := 0
	for i := 0; i < N; i++ {
		snuke = nextSnuke(snuke)
		fmt.Println(snuke)
	}
}

func nextSnuke(n int) int {
	ret := -1
	tmp := math.MaxFloat64

	ds := make([]int, 15)
	org := digits(n + 1)
	for i := 0; i < len(org); i++ {
		ds[15-len(org)+i] = org[i]
	}
	for i := len(ds) - 1; i >= 0; i-- {
		if ds[i] != 9 {
			for j := i + 1; j < len(ds); j++ {
				ds[j] = 9
			}
			for ds[i] != 9 {
				dec := digits2Dec(ds)
				e := eval(dec)
				if e < tmp {
					tmp = e
					ret = dec
				}
				ds[i]++
			}
		}
	}
	return ret
}

func eval(n int) float64 {
	return float64(n) / float64(S(n))
}

func S(n int) int {
	ret := 0
	for _, d := range digits(n) {
		ret = ret + d
	}
	return ret
}

func digits2Dec(digits []int) int {
	ret := 0
	for i := 0; i < len(digits); i++ {
		ret = ret*10 + digits[i]
	}
	return ret
}

func digits(n int) []int {
	ret := make([]int, 0)
	for n > 0 {
		ret = append([]int{n % 10}, ret...)
		n = n / 10
	}
	return ret
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}