This page is still under construction.

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

The Fox and the Owl

Time limit1sMemory limit256 MB

Summary
Given a huge integer N, print the largest integer below N whose digit sum is exactly one more than that of N.
Level

Medium7 of 10

Topics
Greedy, String, Math
Solved
No attempts yet

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 NN, tell me the closest number smaller than NN whose digit sum is one bigger than the digit sum of NN."

Do the owl's job. Given an integer NN, find the biggest integer smaller than NN whose digit sum is exactly one bigger than the digit sum of NN.

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 −20-20 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 NN (∣N∣≤10100000|N| \le 10^{100000}), and the last line contains END and nothing else. NN is written without leading zeros, and a negative NN starts with a minus sign. The total number of digits in the input does not exceed 10610^6.

Output

For each test case print the integer the owl asks for on its own line.

Examples2

  1. Example 1

    Input
    22
    20
    30
    END
    
    Expected output
    14
    12
    22
    
  2. Example 2

    Input
    0
    -1
    -20
    END
    
    Expected output
    -1
    -2
    -21