Gug likes palindromes, so he built an AI to tell if a number is a palindrome. When given a number N, she will say "N is almost a palindrome. It is only X away from the nearest palindrome."
Help Gug's AI find X, the distance to the nearest palindrome
A palindrome is a number that reads the same backward as forward, for example, 1234321, 0 and 10001 are palindromes, but 1112, 100, and 123211 is not. Numbers with leading 0s like 010 are not allowed.
The distance between 2 numbers a and b is defined as |a-b|.
The input will consist of one line, the number N as defined above.
The output should contain one line with the integer X as defined above.
Subtask 1(1%): 0 < N < 10
Subtask 2(17%): 0 < N < 106
Subtask 3(29%): 0 < N < 1012
Subtask 4(53%): 0 < N < 1018
Subtask 5(0%): Sample
12
1
19
3
Subtask | Score |
---|---|
1 | 1 |
2 | 17 |
3 | 29 |
4 | 53 |
5 | 0 |