eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Are We There Yet?

Are We There Yet?

Лимит времени 1 секунда
Лимит использования памяти 64 MiB

A palindrome is a word or sentence that has the same sequence of letters and/or digits when it is read forward or backward; spaces, punctuation, and capitalization are usually ignored. For example, "Aha! Mob Omaha!" and the very short "Lion Oil" are palindromes.

Consider a six-digit odometer in a car that displays the total number of miles the car has been driven; no digits are displayed for fractional miles. Also ignore leading non-significant zeros in the odometer reading, so that "002345" is considered the same as "2345". With these rules, some odometer readings, such as "002332" or "056765" are palindromes. Also note that some of these palindromic numbers have an even number of digits and others have an odd number of digits.

Given the current odometer reading on a car, calculate the number of miles the car must be driven to cause the odometer to display a palindrome.

Example: The current odometer reading is 005432. The next odometer reading that will be a palindrome is 005445, so the number of miles that must be driven is 13.

The problem: Write a program that reads an odometer reading and displays the number of miles to the next odometer reading that will be a palindrome, and that palindrome.

Входные данные

There will be an arbitrary number of odometer readings in the input, each given as a line containing 6 decimal digits and the end of line character. A line containing -1 and the end of line character will follow the last odometer reading.

Выходные данные

For each odometer reading in the input, calculate the number of miles to the closest odometer reading that is a palindrome. Display the input case number (1, 2, …), the number of miles that must be driven, and the corresponding palindromic odometer reading. Follow the format of the output shown below in the sample.

Пример

Входные данные #1
005432
000012
100002
000005
-1
Выходные данные #1
Case 1: 13 miles to 005445.
Case 2: 10 miles to 000022.
Case 3: 1099 miles to 101101.
Case 4: 0 miles to 000005.
Источник ACM North Central North America Regional Programming Contest, November 12, 2011