Valentine's Day '18 J4 & S1 - Carol's Cute Cactus

View as PDF

Submit solution

Points: 7
Time limit: 2.75s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Carol is buying water for her Cactus. However her Cactus has a problem - he simply does not understand how much water is too much water. However, it is essential that she keep water away from her Cactus, for the Cactus will go seek out more water and then die of water overdose.

Thus, Carol needs a way to calculate the perfect amount of water required to quench her Cactus' thirst.

She gives you N, the minimum amount of water Cactus must drink to stay alive, and M, the amount of water that will cause water overdose and death. Carol discovered that she can prevent Cactus from seeking out more water by presenting the water at a cute number, thus distracting Cactus.

A cute number is a number that is palindromic. e.g. 11\,111 is cute, and 1\,001 is cute. Find the palindromic number that is farthest from N and M as possible. This would be the maximum of the smaller of the two absolute differences. If there are multiple cute numbers equally far apart, then use the highest, as more water makes Cactus happy.


1 \le N, M \le 10^8

Input Specification

The first line will contain N and M, the minimum and maximum water value.

Output Specification

The amount of water that Carol should purchase for her Cactus. The input data are set such that Carol will be able to purchase water for her Cactus.

Sample Input

1000 5000

Sample Output


Sample Input

234 2343

Sample Output



There are no comments at the moment.