This page is still under construction.

Parts of this page are still being built. What you see may change.

The Strange Sequence

Time limit1sMemory limit128 MB

Summary
Given a start value and index n, build the sequence where each next term is the smallest number greater than the previous one whose digit sum equals the digit sum of four times the previous term, then print the n-th term.
Level

Medium6 of 10

Topics
Implementation, Math, Greedy, Simulation
Solved
No attempts yet

Problem

Consider a sequence of positive integers a1,a2,a3,…a_1, a_2, a_3, \dots. The first term a1a_1 is given. For every i>1i > 1, the term aia_i is the smallest integer that satisfies both of the following conditions:

  1. ai>ai−1a_i > a_{i-1};
  2. the digit sum of aia_i equals the digit sum of 4⋅ai−14 \cdot a_{i-1}.

Given the first term a1a_1 and an index nn, output the value of ana_n.

Input

A single line contains two integers a1a_1 and nn separated by a space (0<a1<200 < a_1 < 20, 0<n<100000 < n < 10000).

Output

Print a single integer: the value of ana_n. All test data are chosen so that ana_n does not exceed 10910^9.

Examples1

  1. Example 1

    Input
    4 5
    
    Expected output
    79