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 (Python):
print(*[1, 2, 3, 4, 5, 6, 7, 8, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 199, 299, 399, 499, 599, 699, 799, 899, 999, 1099, 1199, 1299, 1399, 1499, 1599, 1699, 1799, 1899, 1999, 2999, 3999, 4999, 5999, 6999, 7999, 8999, 9999, 10999, 11999, 12999, 13999, 14999, 15999, 16999, 17999, 18999, 19999, 20999, 21999, 22999, 23999, 24999, 25999, 26999, 27999, 28999, 29999, 39999, 49999, 59999, 69999, 79999, 89999, 99999, 109999, 119999, 129999, 139999, 149999, 159999, 169999, 179999, 189999, 199999, 209999, 219999, 229999, 239999, 249999, 259999, 269999, 279999, 289999, 299999, 309999, 319999, 329999, 339999, 349999, 359999, 369999, 379999, 389999, 399999, 499999, 599999, 699999, 799999, 899999, 999999, 1099999, 1199999, 1299999, 1399999, 1499999, 1599999, 1699999, 1799999, 1899999, 1999999, 2099999, 2199999, 2299999, 2399999, 2499999, 2599999, 2699999, 2799999, 2899999, 2999999, 3099999, 3199999, 3299999, 3399999, 3499999, 3599999, 3699999, 3799999, 3899999, 3999999, 4099999, 4199999, 4299999, 4399999, 4499999, 4599999, 4699999, 4799999, 4899999, 4999999, 5999999, 6999999, 7999999, 8999999, 9999999, 10999999, 11999999, 12999999, 13999999, 14999999, 15999999, 16999999, 17999999, 18999999, 19999999, 20999999, 21999999, 22999999, 23999999, 24999999, 25999999, 26999999, 27999999, 28999999, 29999999, 30999999, 31999999, 32999999, 33999999, 34999999, 35999999, 36999999, 37999999, 38999999, 39999999, 40999999, 41999999, 42999999, 43999999, 44999999, 45999999, 46999999, 47999999, 48999999, 49999999, 50999999, 51999999, 52999999, 53999999, 54999999, 55999999, 56999999, 57999999, 58999999, 59999999, 69999999, 79999999, 89999999, 99999999, 109999999, 119999999, 129999999, 139999999, 149999999, 159999999, 169999999, 179999999, 189999999, 199999999, 209999999, 219999999, 229999999, 239999999, 249999999, 259999999, 269999999, 279999999, 289999999, 299999999, 309999999, 319999999, 329999999, 339999999, 349999999, 359999999, 369999999, 379999999, 389999999, 399999999, 409999999, 419999999, 429999999, 439999999, 449999999, 459999999, 469999999, 479999999, 489999999, 499999999, 509999999, 519999999, 529999999, 539999999, 549999999, 559999999, 569999999, 579999999, 589999999, 599999999, 609999999, 619999999, 629999999, 639999999, 649999999, 659999999, 669999999, 679999999, 689999999, 699999999, 799999999, 899999999, 999999999, 1099999999, 1199999999, 1299999999, 1399999999, 1499999999, 1599999999, 1699999999, 1799999999, 1899999999, 1999999999, 2099999999, 2199999999, 2299999999, 2399999999, 2499999999, 2599999999, 2699999999, 2799999999, 2899999999, 2999999999, 3099999999, 3199999999, 3299999999, 3399999999, 3499999999, 3599999999, 3699999999, 3799999999, 3899999999, 3999999999, 4099999999, 4199999999, 4299999999, 4399999999, 4499999999, 4599999999, 4699999999, 4799999999, 4899999999, 4999999999, 5099999999, 5199999999, 5299999999, 5399999999, 5499999999, 5599999999, 5699999999, 5799999999, 5899999999, 5999999999, 6099999999, 6199999999, 6299999999, 6399999999, 6499999999, 6599999999, 6699999999, 6799999999, 6899999999, 6999999999, 7099999999, 7199999999, 7299999999, 7399999999, 7499999999, 7599999999, 7699999999, 7799999999, 7899999999, 7999999999, 8999999999, 9999999999, 10999999999, 11999999999, 12999999999, 13999999999, 14999999999, 15999999999, 16999999999, 17999999999, 18999999999, 19999999999, 20999999999, 21999999999, 22999999999, 23999999999, 24999999999, 25999999999, 26999999999, 27999999999, 28999999999, 29999999999, 30999999999, 31999999999, 32999999999, 33999999999, 34999999999, 35999999999, 36999999999, 37999999999, 38999999999, 39999999999, 40999999999, 41999999999, 42999999999, 43999999999, 44999999999, 45999999999, 46999999999, 47999999999, 48999999999, 49999999999, 50999999999, 51999999999, 52999999999, 53999999999, 54999999999, 55999999999, 56999999999, 57999999999, 58999999999, 59999999999, 60999999999, 61999999999, 62999999999, 63999999999, 64999999999, 65999999999, 66999999999, 67999999999, 68999999999, 69999999999, 70999999999, 71999999999, 72999999999, 73999999999, 74999999999, 75999999999, 76999999999, 77999999999, 78999999999, 79999999999, 80999999999, 81999999999, 82999999999, 83999999999, 84999999999, 85999999999, 86999999999, 87999999999, 88999999999, 89999999999, 99999999999, 109999999999, 119999999999, 129999999999, 139999999999, 149999999999, 159999999999, 169999999999, 179999999999, 189999999999, 199999999999, 209999999999, 219999999999, 229999999999, 239999999999, 249999999999, 259999999999, 269999999999, 279999999999, 289999999999, 299999999999, 309999999999, 319999999999, 329999999999, 339999999999, 349999999999, 359999999999, 369999999999, 379999999999, 389999999999, 399999999999, 409999999999, 419999999999, 429999999999, 439999999999, 449999999999, 459999999999, 469999999999, 479999999999, 489999999999, 499999999999, 509999999999, 519999999999, 529999999999, 539999999999, 549999999999, 559999999999, 569999999999, 579999999999, 589999999999, 599999999999, 609999999999, 619999999999, 629999999999, 639999999999, 649999999999, 659999999999, 669999999999, 679999999999, 689999999999, 699999999999, 709999999999, 719999999999, 729999999999, 739999999999, 749999999999, 759999999999, 769999999999, 779999999999, 789999999999, 799999999999, 809999999999, 819999999999, 829999999999, 839999999999, 849999999999, 859999999999, 869999999999, 879999999999, 889999999999, 899999999999, 909999999999, 919999999999, 929999999999, 939999999999, 949999999999, 959999999999, 969999999999, 979999999999, 989999999999, 999999999999, 1099999999999, 1199999999999, 1299999999999, 1399999999999, 1499999999999, 1599999999999, 1699999999999, 1799999999999, 1899999999999, 1999999999999, 2099999999999, 2199999999999, 2299999999999, 2399999999999, 2499999999999, 2599999999999, 2699999999999, 2799999999999, 2899999999999, 2999999999999, 3099999999999, 3199999999999, 3299999999999, 3399999999999, 3499999999999, 3599999999999, 3699999999999, 3799999999999, 3899999999999, 3999999999999, 4099999999999, 4199999999999, 4299999999999, 4399999999999, 4499999999999, 4599999999999, 4699999999999, 4799999999999, 4899999999999, 4999999999999, 5099999999999, 5199999999999, 5299999999999, 5399999999999, 5499999999999, 5599999999999, 5699999999999, 5799999999999, 5899999999999, 5999999999999, 6099999999999, 6199999999999, 6299999999999, 6399999999999, 6499999999999, 6599999999999, 6699999999999, 6799999999999, 6899999999999, 6999999999999, 7099999999999, 7199999999999, 7299999999999, 7399999999999, 7499999999999, 7599999999999, 7699999999999, 7799999999999, 7899999999999, 7999999999999, 8099999999999, 8199999999999, 8299999999999, 8399999999999, 8499999999999, 8599999999999, 8699999999999, 8799999999999, 8899999999999, 8999999999999, 9099999999999, 9199999999999, 9299999999999, 9399999999999, 9499999999999, 9599999999999, 9699999999999, 9799999999999, 9899999999999, 9999999999999, 10999999999999, 11999999999999, 12999999999999, 13999999999999, 14999999999999, 15999999999999, 16999999999999, 17999999999999, 18999999999999, 19999999999999, 20999999999999, 21999999999999, 22999999999999, 23999999999999, 24999999999999, 25999999999999, 26999999999999, 27999999999999, 28999999999999, 29999999999999, 30999999999999, 31999999999999, 32999999999999, 33999999999999, 34999999999999, 35999999999999, 36999999999999, 37999999999999, 38999999999999, 39999999999999, 40999999999999, 41999999999999, 42999999999999, 43999999999999, 44999999999999, 45999999999999, 46999999999999, 47999999999999, 48999999999999, 49999999999999, 50999999999999, 51999999999999, 52999999999999, 53999999999999, 54999999999999, 55999999999999, 56999999999999, 57999999999999, 58999999999999, 59999999999999, 60999999999999, 61999999999999, 62999999999999, 63999999999999, 64999999999999, 65999999999999, 66999999999999, 67999999999999, 68999999999999, 69999999999999, 70999999999999, 71999999999999, 72999999999999, 73999999999999, 74999999999999, 75999999999999, 76999999999999, 77999999999999, 78999999999999, 79999999999999, 80999999999999, 81999999999999, 82999999999999, 83999999999999, 84999999999999, 85999999999999, 86999999999999, 87999999999999, 88999999999999, 89999999999999, 90999999999999, 91999999999999, 92999999999999, 93999999999999, 94999999999999, 95999999999999, 96999999999999, 97999999999999, 98999999999999, 99999999999999, 100999999999999, 101999999999999, 102999999999999, 103999999999999, 104999999999999, 105999999999999, 106999999999999, 107999999999999, 108999999999999, 109999999999999, 119999999999999, 129999999999999, 139999999999999, 149999999999999, 159999999999999, 169999999999999, 179999999999999, 189999999999999, 199999999999999, 209999999999999, 219999999999999, 229999999999999, 239999999999999, 249999999999999, 259999999999999, 269999999999999, 279999999999999, 289999999999999, 299999999999999, 309999999999999, 319999999999999, 329999999999999, 339999999999999, 349999999999999, 359999999999999, 369999999999999, 379999999999999, 389999999999999, 399999999999999, 409999999999999, 419999999999999, 429999999999999, 439999999999999, 449999999999999, 459999999999999, 469999999999999, 479999999999999, 489999999999999, 499999999999999, 509999999999999, 519999999999999, 529999999999999, 539999999999999, 549999999999999, 559999999999999, 569999999999999, 579999999999999, 589999999999999, 599999999999999, 609999999999999, 619999999999999, 629999999999999, 639999999999999, 649999999999999, 659999999999999, 669999999999999, 679999999999999, 689999999999999, 699999999999999, 709999999999999, 719999999999999, 729999999999999, 739999999999999, 749999999999999, 759999999999999, 769999999999999, 779999999999999, 789999999999999, 799999999999999, 809999999999999, 819999999999999, 829999999999999, 839999999999999, 849999999999999, 859999999999999, 869999999999999, 879999999999999, 889999999999999, 899999999999999, 909999999999999, 919999999999999, 929999999999999, 939999999999999, 949999999999999, 959999999999999, 969999999999999, 979999999999999, 989999999999999, 999999999999999][:int(input())])

Solution (Python):
import numpy as np

def set_power(a, power_array):
    res = 1
    for i in range(len(power_array)):
        power_array[i] = res
        res *= a


def solve(ans, K, arr):
    p = 0
    for d in range(15):
        pow = arr[d]
        x = pow - 1
        for i in range(1, 10):
            if d > 2:
                y = i * pow + arr[d - 1] - 1
                if y <= (9*(d - 1) + 1)*arr[d - 1]:
                    for j in range(0, 9):
                        if d > 9:
                            z = i*pow + j*arr[d - 1] + arr[d - 2] - 1
                            if z <= (9 * (d - 2) + j + 1) * arr[d - 2]:
                                for j2 in range(0, 9):
                                    ans[p] = z + j2 * arr[d - 2]
                                    p += 1
                        ans[p] = y + j * arr[d - 1]
                        p += 1
            ans[p] = i * pow + x
            p += 1
    return p

K = int(input())
ans = np.empty(10000, dtype=np.int64)
power_array = np.empty(16, dtype=np.int64)
set_power(10, power_array)
p = solve(ans, K, power_array)
print(*ans[:K].tolist(), sep='\n')

Solution (Python):
def snuke(n) :
    s=sum(map(int,str(n)))
    return n/s

k=int(input())
digit=0
ans=1
for _ in range(k):
    print(ans)
    if snuke(ans+10**digit)>snuke(ans+10**(digit+1)):
        digit+=1
    ans+=10**digit

Solution (Python):
K = int(input())

def calc_sunuke(num):
    st = str(num)
    s_num = 0
    for c in st:
        s_num += int(c)
    return num / s_num

def search_sunuke(num):
    num_sunuke = calc_sunuke(num)
    if num >= 100:
        digits = len(str(num))
        if digits < 12:
            for i in range(count + 10**(digits-2), 10**digits, 10**(digits-2)):
                if num_sunuke > calc_sunuke(i):
                    return False
            return True
        else:
            for i in range(count + 10**(digits-3), 10**digits, 10**(digits-3)):
                if num_sunuke > calc_sunuke(i):
                    return False
            return True
    else:
        for i in range(count+1, 100):
            if num_sunuke > calc_sunuke(i):
                return False
        return True



count = 1
sunuke_num = 0
while sunuke_num != K:
    if search_sunuke(count):
        print(count)
        sunuke_num += 1
    if count < 99:
        count += 1
    else:
        count_str = str(count)
        digits = len(count_str)
        r_count = count
        if digits < 12:
            for c in count_str:
                if c != '9':
                    count += 10**(digits - 2)
                    break
            if r_count == count:
                count += 10**(digits - 1)
        else:
            for c in count_str:
                if c != '9':
                    count += 10**(digits - 3)
                    break
            if r_count == count:
                count += 10**(digits - 2)

Solution (Python):
K = int(input())

def nd(n):
    ans = 0
    nn = n
    while(nn > 0):
        ans += nn%10
        nn //= 10
    return ans/n

def k_next(k):
  d = 1
  c_max = 0
  ans = k
  while(d < k*10):
    cand = (k//d+1)*d+(k%d)
    if nd(cand) >= c_max:
      c_max = nd(cand)
      ans = cand
    d *= 10
  return ans

k = 1
for i in range(K):
  print(k)
  k = k_next(k)

Solution (Python):
K = int(input())

def sunuke(n) :
    sumN = sum(map(int, list(str(n))))
    return n / sumN

digit = 0
now = 1

for i in range(K) :
    print(now)
    if sunuke(now + 10**digit) > sunuke(now + 10**(digit + 1)) :
        digit += 1
    now += 10**digit

Solution (Python):
k=int(input())
ans=[]
for i in range(1,10): 
  ans.append(str(i))
  
for i in range(1,10): 
  ans.append(str(i)+'9')
  
for i in range(1,10): 
  ans.append(str(i)+'99')
  
for i in range(10): 
  ans.append('1'+str(i)+'99')
for i in range(2,10): 
  ans.append(str(i)+'999')
  
for i in range(1,3): 
  for j in range(10):
    ans.append(str(i)+str(j)+'999')
for i in range(3,10): 
  ans.append(str(i)+'9999')
  
for i in range(1,4): 
  for j in range(10):
    ans.append(str(i)+str(j)+'9999')
for i in range(4,10): 
  ans.append(str(i)+'99999')
  
for i in range(1,5): 
  for j in range(10):
    ans.append(str(i)+str(j)+'99999')
for i in range(5,10): 
  ans.append(str(i)+'999999')

for i in range(1,6): 
  for j in range(10):
    ans.append(str(i)+str(j)+'999999')
for i in range(6,10): 
  ans.append(str(i)+'9999999')
  
for i in range(1,7): 
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999')
for i in range(7,10): 
  ans.append(str(i)+'99999999')

for i in range(1,8): 
  for j in range(10):
    ans.append(str(i)+str(j)+'99999999')
for i in range(8,10): 
  ans.append(str(i)+'999999999')

for i in range(1,9): 
  for j in range(10):
    ans.append(str(i)+str(j)+'999999999')
for i in range(9,10): 
  ans.append(str(i)+'9999999999')
  
for i in range(1,10): 
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999999')
for i in range(10,10): 
  ans.append(str(i)+'99999999999')

for i in range(1,10): 
  for j in range(10):
    ans.append(str(i)+str(j)+'99999999999')
for i in range(10,10): 
  ans.append(str(i)+'999999999999')
  
for i in range(1,10): 
  for j in range(10):
    ans.append(str(i)+str(j)+'999999999999')
for i in range(10,10): 
  ans.append(str(i)+'9999999999999')

for i in range(10): 
  ans.append('10'+str(i)+'999999999999')
for i in range(1,10): 
  ans.append('1'+str(i)+'9999999999999')
for i in range(2,10): 
  for j in range(10):
    ans.append(str(i)+str(j)+'9999999999999')
  
for val in ans[:k]:
  print(val)

Solution (Python):
def s(n):
    ret = 0
    while n > 0:
        ret += n % 10
        n //= 10
    return ret

numbers = [999999999999999999]
while numbers[-1] > 1:
    for d in range(0, 100):
        n = numbers[-1]
        m = n - 10 ** d
        if n * s(m) >= m * s(n):
            numbers.append(m)
            break
numbers = list(reversed(numbers))

n = int(input())
for i in range(n):
    print(numbers[i])

Solution (Python):
def snu(n):
    s=str(n)
    kei=sum(int(x) for x in s)
    return n/kei

def nn(n):
    s=str(n)
    kt=len(str(int(snu(n))))
    if s[-kt:].count("9")==kt:
        if s[-kt-1]=="9":
            n+=10**kt
            s=str(n)
            kt = len(str(int(snu(n))))
            if s[-kt:].count("9") == kt:
                return n
            else:
                s = s[:-kt] + "9" * kt
                return int(s)
        else:
            return n+10**kt
    else:
        s=s[:-kt]+"9"*kt
        return int(s)

k=int(input())
t=9 if k>9 else k
for i in range(1,t+1):
    print(i)
if k<=9:exit()
n=19
for _ in range(k-9):
    print(n)
    n=nn(n)

Solution (Python):
K = int(input())

def minSunuke(n) :  
    sumDigit = sum(map(int, list(str(n))))
    return n / sumDigit

digit = 0
now = 1

for i in range(K) :
    print(now)
    if minSunuke(now + 10**digit) > minSunuke(now + 10**(digit + 1)) :
        digit += 1
    now += 10**digit

Solution (Python):
def digit_sum(n):
    res = 0
    while n > 0:
        res += n % 10
        n /= 10
    return res
k = int(raw_input())
snuke_num = 1
num_of_nums = 0
increment = 1
while num_of_nums < k:
    print snuke_num
    num_of_nums += 1
    candid = snuke_num + increment
    opponent = candid + increment
    if float(candid)/digit_sum(candid) > float(opponent) / digit_sum(opponent):
        increment *= 10
    snuke_num += increment

Solution (Python):
k=int(input())
def s(n):
    m=str(n)
    l=list(m)
    l=map(int,l)
    return n/sum(l)
p=1
q=0
for i in range(k):
    print(p)
    if s(p+10**q)>s(p+10**(q+1)):
        q+=1
    p+=10**q

Solution (Python):
k=int(input())
def s(n):
    m=str(n)
    l=list(m)
    l=map(int,l)
    return n/sum(l)
p=1
q=0
for i in range(k):
    print(p)
    if s(p+10**q)>s(p+10**(q+1)):
        q+=1
    p+=10**q

Solution (Python):
K=int(input())
n=1
k=0
x=[]
y=x.append
while(n<=10**15):
    plus=10**k
    if n>=1350*plus:
        n+=9*plus
        k+=1
        plus*=10
    y([n,n/sum(map(int,list(str(n))))])
    n+=plus
x2=[]
y2=x2.append
min_=10**15
for i in range(len(x)-1,-1,-1):
    if x[i][1]<=min_:
        y2(x[i][0])
        min_=x[i][1]
x2=list(reversed(x2))
for i in range(K):
    print(x2[i])

Solution (Python):
def digitsum(n):
    s = str(n)
    array = list(map(int, s))
    return sum(array)

def list_to_num(l):
    s = 0
    for i in range(len(l)):
        s += l[i]*pow(10,i)
    return s

k = int(input())

def func(a):
    n = a+1
    if a == 0:
        return 1
    elif n/digitsum(n)==1:
        return n
    else:
        s = str(n)
        array = list(map(int, s))[::-1]
        if len(list(set(array)))==1 and list(set(array))[0]==9:
            n =list_to_num(array)+1
            s = str(n)
            array = list(map(int, s))[::-1]
        min = pow(10,15)
        ans = 0
        for i in range(len(array)):
            for j in range(array[i]+1,10):
                array[i] = j
                temp = list_to_num(array)/digitsum(list_to_num(array))
                if temp < min:
                    min = temp
                    ans = list_to_num(array)
        return ans


n = 0
for i in range(k):
    print(func(n))
    n = func(n)

Solution (Python):
K=int(input())
tmp=0
i=0
k=0
res=1
def S(a):
  res=0
  while(a!=0):
    res+=a%10
    a//=10
  return res
def check(i,a):
  if (10**i)*S(a)<a:
    return True
  return False
while(True):
  if k==K:
    break
  print(res)
  k+=1
  res+=10**i
  if check(i,res):
    res-=10**i
    i+=1
    res+=10**i

Solution (Python):








def S(n):
  if n < 10:
    return n
  return S(n//10) + n%10
  
li = [] 

for d in range(20):
  a = 10**d
  for x in range(200):
    y = (x+1)*a-1
    if y > 0:
      z = S(y)
      li.append((y,z))
    
li = sorted(list(set(li)),reverse=True)


answer = []
min_N,min_S = li[0]
for n,s in li[1:]:
  
  if n*min_S <= s*min_N:
    min_N = n
    min_S = s
    answer.append(n)


K = int(input())
answer.sort()
answer = answer[:K]
print('\n'.join(map(str,answer)))

Solution (Python):
k = int(input())
candili = []
for i in range(1, 1000):
    candili.append(i)

tmpli = []
for i in candili:
    for j in range(1, 15):
        tmpli.append(int(str(i) + "9" * j))
tmpli = list(set(tmpli))

tmp2li = []
for i in tmpli:
    if i <= 10 ** 15:
        tmp2li.append(i)
candili += tmp2li
candili = list(set(candili))
candili.sort()

def S(n):
    return sum(int(i) for i in str(n))

conli = []

for i in candili:
    conli.append(i/S(i))

ansli = []
for i in range(len(conli)):
    for j in range(i, len(conli)):
        if conli[i] > conli[j]:
            break
    else:
        ansli.append(candili[i])

for i in range(k):
    print(ansli[i])

Solution (Python):
k = int(input())
candili = []
for i in range(1, 1000):
    candili.append(i)

tmpli = []
for i in candili:
    for j in range(1, 15):
        tmpli.append(int(str(i) + "9" * j))
tmpli = list(set(tmpli))

tmp2li = []
for i in tmpli:
    if i <= 10 ** 15:
        tmp2li.append(i)
candili += tmp2li
candili = list(set(candili))
candili.sort()

def S(n):
    return sum(int(i) for i in str(n))

conli = []

for i in candili:
    conli.append(i/S(i))

ansli = []
for i in range(len(conli)):
    for j in range(i, len(conli)):
        if conli[i] > conli[j]:
            break
    else:
        ansli.append(candili[i])

for i in range(k):
    print(ansli[i])

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance





k = 0

def print_ans(x):
    global k
    print(x)
    k -= 1
    if k <= 0:
        exit(0)
    return x


def s(n):
    ret = 0
    while n:
        ret += n % 10
        n = n // 10
    return ret


def get_anslist(base, msnum, pownum):
    do_break = False
    end = ((msnum + 10) // 10) * 10
    ret = []

    for i in range(msnum, end):
        m = base + i * (10**pownum)
        snuke = m / s(m)
        ret.append((m, snuke))
        if snuke >= (10**pownum):
            do_break = True
    return ret, do_break


def main():
    global k
    k = intin()
    max_print = -1

    for i in range(16):
        base = 0 if i == 0 else int('9' * i)
        msnum = 1
        if max_print >= base:
            msnum = (max_print - base) // (10**i) + 1
        anslist = []

        while True:
            part_anslist, do_break = get_anslist(base, msnum, i)
            anslist.append(part_anslist)
            if do_break:
                break
            msnum = ((msnum + 10) // 10) * 10

        for part_anslist in anslist:
            prev = None
            incr = True
            for ans, snuke in part_anslist:
                if prev is not None and snuke < prev:
                    incr = False
                prev = last = snuke
            if incr:
                for ans, snuke in part_anslist:
                    max_print = print_ans(ans)
            else:
                prev = None
                for ans, snuke in part_anslist:
                    if snuke <= last:
                        max_print = print_ans(ans)
                    if prev is not None and prev > snuke:
                        break
                    prev = snuke


if __name__ == '__main__':
    main()

Solution (Python):

def funuke(now):
    count = 0
    for ele in list(str(now)):
        count += int(ele)
    return now / count

def main():
    num = int(input())

    keta = 1
    now = 1
    count = 0

    while count < num:
        if funuke(now) <= funuke(now + keta):
            count += 1
            print(now)
            now += keta
        else:
            now += 9 * keta
            keta *= 10

if __name__ == '__main__':
    main()

Solution (Python):

K=int(input())
keta=1
now=1
count=0

def sunuke(n):
    a=0
    for i in str(n):
        a+=int(i)
    return(n/a)

while count < K:
    if sunuke(now) <= sunuke(now+keta):
        print(now)
        now+=keta
        count+=1
    else:
        now+=9*keta
        keta*=10

Solution (Python):
K = int(input())
 
def f(n):
    return n / sum([int(s) for s in str(n)])

ans = [1]
for k in range(K - 1):
    min_f_val, next_snuke = float('inf'), None
    n = str(ans[-1] + 1)
    for i in range(len(n)):
        for x in range(int(n[i]), 10):
            X = n[:i] + str(x) + '9' * (len(n) - i - 1)
            f_val = f(int(X))
            if f_val < min_f_val:
                next_snuke = int(X)
                min_f_val = f_val
    ans.append(next_snuke)
print(*ans, sep='\n')

Solution (Python):
k = int(input())
keta = 1
ima = 1
def sunuke(n) :
    a = 0
    for i in str(n) :
        a += int(i)
    return(n/a)
count = 0
while count < k :
    if sunuke(ima) <= sunuke(ima+keta) :
        print(ima)
        ima += keta
        count += 1
    else :
        ima += 9*keta
        keta *= 10

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log10
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

K = INT()

def S(n): 
	return sum([int(x) for x in list(n)])

def f(N):
	sunuke = []
	for d in range(-1, int(log10(N)+1)):
		sunuke.append(10**(d+1) * (N//(10**(d+1))+1)-1)
	sunuke2 = [x/S(str(x)) for x in sunuke]
	return sunuke[sunuke2.index(min(sunuke2))]

N = 1
for _ in range(K):
	print(N)
	N = f(N+1)

Solution (Python):
K = int(input())


def f(n):
    return n / sum([int(s) for s in str(n)])


ans = [1]
for k in range(K - 1):
    min_f_val, next_snuke = float('inf'), None
    n = str(ans[-1] + 1)

    for i in range(len(n)):
        for x in range(int(n[i]), 10):
            X = n[:i] + str(x) + '9' * (len(n) - i - 1)
            f_val = f(int(X))

            if f_val < min_f_val:
                next_snuke = int(X)
                min_f_val = f_val

    ans.append(next_snuke)

print(*ans, sep='\n')

Solution (Python):
K = int(input())



snukePairs = []

for i in range(1, 16):
    top = 1  
    if i >= 12:
        top = 3
    elif i >= 4:
        top = 2
    p = pow(10, i - top)
    fill9 = p - 1
    top_num = pow(10, max(top, 1)) 
    check_index = len(snukePairs)
    for j in range(pow(10, top - 1), top_num):
        num = j * p + fill9
        nn = num
        s = 0
        
        while nn > 0:
            s += nn % 10
            nn = nn // 10
        val = num / s

        
        idx = len(snukePairs) - 1
        while idx >= 0:
            if snukePairs[idx][1] > val:
                del snukePairs[idx]
            idx -= 1
        snukePairs.append([num, val])

for i in range(0, K):
    print(snukePairs[i][0])

Solution (Python):
def cal(n):
    m = n
    ret = 0
    while n != 0:
        ret += n % 10
        n //= 10
    return m/ret


def f(n):
    cand = []
    s = str(n)
    for i in range(len(s)-1,-1,-1):
        if s[i] == "9":
            continue
        for j in range(int(s[i]), 10):
            t = int(s[:i] + str(j) + s[i+1:])
            cand += [ t ]
        s = s[:i] + "9" + s[i+1:]

    ret = n
    for x in cand:
        if cal(x) < cal(ret):
            ret = x
    return ret 


k = int(input())
ans = 1

for _ in range(k):
    print(ans)
    ans = f(ans+1)

Solution (Python):
k = int(input())

def f(num):
  return num / sum(map(int, list(str(num))))

order = 0
sunuke = 1
for i in range(k):
  print(sunuke)
  sunuke += 10**order
  if f(sunuke + 10**(order+1)) < f(sunuke + 10**order):
    order += 1

Solution (Python):
k = int(input())

def s(n):
    r = 0
    while n > 0:
        r += n % 10
        n = n // 10
    return r
    

def find_next(n):
    d = 0
    m = n // 10
    sm = s(m)
    r = 0
    grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    while grad > 0:
        r += 9 * 10**d
        d += 1
        sm -= m % 10
        m = m // 10
        grad = 10 * m + 1 - sm - 9 * d - 1/(10**d)
    r += (n // 10**d) * 10**d
    return r

for i in range(1, min(k, 9) + 1):
    print(i)
    
k -= min(k, 9)
p = 10

for i in range(0, k):
    p = find_next(p)
    print(p)
    p += 1

Solution (Python):
k = int(input())

cnt = 0
step = 1
base = 1
tail = ""
now = 0
def f(x):
    s = list(str(x))
    return sum([int(i) for i in s])
while 1:
    now += step
    if now > step*f(now):
        now -= step
        step *= 10
    else:
        cnt += 1
        print(now)
        if cnt == k:
            exit(0)