The Fox and the Owl
Time limit1sMemory limit256 MB
Given a huge integer N, print the largest integer below N whose digit sum is exactly one more than that of N.
Problem
Fox Mithra has finally learned the numbers. He knows one, two, three, and also zero, minus one, minus two. He took his textbook and copied the integers onto the wall of his enclosure at the zoo, one by one, from the smallest to the biggest.
An owl landed on the branch above Mithra's head. "Something is wrong with the sequence on your wall," she said. "You should put 30 between 20 and 22."
"Why?"
"Because the importance of a number is judged by the sum of its digits. 30 is less important than 22 and more important than 20. The digit sum of 30 differs by exactly one from the digit sum of 20 and from the digit sum of 22, so 30 belongs right between them."
"I see. Please help me fix the order. Each time I tell you a number , tell me the closest number smaller than whose digit sum is one bigger than the digit sum of ."
Do the owl's job. Given an integer , find the biggest integer smaller than whose digit sum is exactly one bigger than the digit sum of .
The digit sum of an integer is the sum of the digits of its decimal notation, and a negative integer uses the digit sum of its absolute value. For example, the digit sum of is 2. Such an integer always exists and it is unique. The answer is sometimes negative.
Input
The input holds several test cases. Each line contains one integer (), and the last line contains END and nothing else. is written without leading zeros, and a negative starts with a minus sign. The total number of digits in the input does not exceed .
Output
For each test case print the integer the owl asks for on its own line.