#K49657. Minimum Digits to Make Palindrome

    ID: 28691 Type: Default 1000ms 256MiB

Minimum Digits to Make Palindrome

Minimum Digits to Make Palindrome

Given a positive integer (x), determine the minimum number of digits that need to be added to the beginning of (x) so that the resulting number becomes a palindrome. A number is palindromic if it reads the same forwards and backwards.

For example, if (x = 123), then by adding 2 digits (to form, for instance, "32123") you can obtain a palindrome; hence, the answer is 2. In other words, if the decimal representation of (x) is given by a string (s), you are to find the smallest non-negative integer (k) such that the substring (s[k:]) is a palindrome.

inputFormat

The input consists of a single line containing a positive integer (x).

outputFormat

Output a single integer, which is the minimum number of digits required to be added at the beginning to form a palindromic number.## sample

123
2