#P4109. The Most Absurd Price

    ID: 17357 Type: Default 1000ms 256MiB

The Most Absurd Price

The Most Absurd Price

Many goods in the market are priced in a way that seems psychologically appealing, such as 999, 4999, or 8999. Although these prices are essentially not much different from rounded figures like 1000, 5000, or 9000, they give a perception of being cheaper. In this problem, you consider these prices absurd and define an absurdity measure for a given positive integer price \(p\) as follows:

1. Treat \(p\) as a string of digits (without any leading zero).
2. While the last character of \(p\) is \(0\), remove it. (Repeat this process until the last digit is not \(0\)).
3. Let \(a\) be the length of the resulting string. If the last digit is \(5\), the absurdity is \(2a-1\); otherwise it is \(2a\).

For example, the absurdity of 850 is computed as follows: 850 becomes "85" after removing the trailing zero; \(a=2\) and since the last digit is 5, the absurdity is \(2 \times 2-1 = 3\). Similarly, 880 becomes "88" (\(a=2\)) and its absurdity is \(2 \times 2 = 4\); 9999 has no trailing zeros so \(a=4\) and the absurdity is \(2 \times 4 = 8\>.

You have an item to sell and you are willing to set the price within the range \([L, R]\). Your task is to choose a price within this range that has the minimum possible absurdity. If there are several such prices, output any one of them.

inputFormat

The input consists of a single line containing two space-separated integers \(L\) and \(R\) (\(1 \leq L \leq R\)).

outputFormat

Output one integer, which is a price in the range \([L, R]\) with the minimum absurdity. If multiple answers exist, any one is acceptable.

sample

850 900
850