JOIN
Get Time

   Problem Statement  

 Problem Statement for PalindromizationDiv2

Problem Statement

    Little Arthur loves numbers, especially palindromic ones. A palindromic string is a string that reads the same both forwards and backwards. A palindromic number is a non-negative integer such that its decimal representation (without insignificant leading zeros) is a palindromic string. For example, 12321, 101, 9, and 0 are palindromic numbers but 2011, 509, and 40 are not.



Arthur has a number X and he would like to palindromize it. Palindromization of a number means adding or subtracting some value to obtain a palindromic number. For example, one possible way to palindromize number 25 is adding 8 resulting in number 33, which is palindromic.



Unfortunately Arthur cannot palindromize numbers for free. The cost of palindromization in dollars is equal to the value added or subtracted. In the previous example Arthur would have to pay 8 dollars.



Of course Arthur would like to palindromize X spending the least amount of money. Given X return the minimum amount of money Arthur needs.
 

Definition

    
Class:PalindromizationDiv2
Method:getMinimumCost
Parameters:int
Returns:int
Method signature:int getMinimumCost(int X)
(be sure your method is public)
    
 

Constraints

-X will be between 0 and 100000 (10^5), inclusive.
 

Examples

0)
    
25
Returns: 3
In the problem statement it is shown that adding 8 to 25 results in a palindromic number 33. However, this is not the cheapest way to palindromize 25. Arthur can subtract 3 to obtain a number 22 which is also palindromic.
1)
    
12321
Returns: 0
Already a palindromic number.
2)
    
40
Returns: 4
3)
    
2011
Returns: 9
4)
    
0
Returns: 0

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.

This problem was used for:
       Single Round Match 509 Round 1 - Division II, Level One