Tianjin University Online Judge
Contests Virtual Contests Problems Submit Runs Status Rank List Forum

2974.   Digital Rivers
Time Limit: 1.0 Seconds   Memory Limit: 65536K
Total Runs: 130   Accepted Runs: 88



A digital river is a sequence of number where the number following n in n plus the sum of its digits. For example, 12345 is followed by 12360, since 1+2+3+4+5=15. If the first number of a digital river is k we will call it river k.

For example, river 480 is the sequence beginning {480,492,507,519,..} and river 483 is the sequence beginning {483,498,519,..}.

Normal streams and rivers can meet, and the same is true for digital rivers. This happens when two digital rivers share some of the same values. For example: river 480 meets river 483 at 519, meets river 507 at 507 and never meets river 481.

Every digital river will eventually meet river 1, river 3 or river 9. Write a program that can determine for a given integer n the value where river n first meets one of these three rivers.

Input

The input may contain multiple test cases. Each case occupies a separate line and contains an integer n (1≤n≤16384). A test case with value of 0 for n terminates the input and this test case must not be processed.

Output

For each test case in the input, output a line containing an integer x followed by another integer y on the same line. Here y is the lowest value where river n first meets river x (x=1 or 3 or 9). If river n meets river x at y for more than one value of x, output the lowest value. Separate x and y by a white space character.

Sample Input

86
12345
0

Sample Output

1 101
3 12423

Problem Setter: Md. Shakil Ahmed.



Source: CUET Easy Contest
Submit   List    Runs   Forum   Statistics

Tianjin University Online Judge v1.2.4