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 Ruby (2.7.1) (judge verdict: Wrong Answer)

#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

K = get_int

# X = 1.step(1000000).map do |n|
#   [n, (n.to_f/ n.to_s.split('').map(&:to_i).sum)]
# end
#
# X.sort! { |a, b| a[1] <=> b[1] }
# xx = []
# max = 0
# X.each do |x|
#   if x[0] > max
#     xx << x
#     max = x[0]
#   end
# end

x = 1
def next_x(x)
  if x.to_s.length < 3
    x+1
  else
    a = x.to_s.split('')[0..1].join.to_i
    ((a+1).to_s + ('9' * (x.to_s.length - 2))).to_i
  end
end

x = 1
ans = [1]
while x <= 10 ** 15
  x = next_x(x)
  ans << x
end

ans.map! { |n| [n,(n.to_f/ n.to_s.split('').map(&:to_i).sum)] }
ans.sort! do |a, b|
  if (a[1] <=> b[1]) == 0
    a[0] <=> b[0]
  else
    a[1] <=> b[1]
  end
end

xx = []
max = 0
ans.each do |x|
  if x[0] > max
    xx << x
    max = x[0]
  end
end

K.times do |i|
  puts ans[i][0]
end