1665.Reflection

Time Limit: 1s Memory Limit: 256MB

For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9-a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that leading zeros (if any) should be omitted. So reflection of 9 equals 0, reflection of 91 equals 8.

Let us call the weight of the number the product of the number and its reflection. Thus, the weight of the number 10 is equal to 10 \cdot 89=890.

Your task is to find the maximum weight of the numbers in the given range [l,r] (boundaries are included).

Input Format(From the terminal/stdin)

Input contains two space-separated integers l and r (1 \le l \le r \le 109) - bounds of the range.

Output Format(To the terminal/stdout)

Output should contain single integer number: maximum value of the product n \cdot ψ(n), where l \le n \le r.

Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout (also you may use %I64d).

Sample Input 1

Copy
3 7
 · \n

Sample Output 1

Copy
20
  \n

Sample Input 2

Copy
1 1
 · \n

Sample Output 2

Copy
8
 \n

Sample Input 3

Copy
8 10
 ·  \n

Sample Output 3

Copy
890
   \n

Hints

In the third sample weight of 8 equals 8 \cdot 1=8, weight of 9 equals 9 \cdot 0=0, weight of 10 equals 890.

Thus, maximum value of the product is equal to 890.

Submit

请先 登录

© 2025 FAQs