Subtraction
Donald wants to play with integers. He is especially interested in integers that, when their digits are read backwards (from right to left), produce a larger number. For example, if we reverse the digits of 123 we get 321, if we reverse the digits of 459 we get 954 (and 954 > 459), etc.
Let’s say we have some initial number N, and we can also reverse its digits and get the number R. Donald is currently writing a thesis on the value of the subtraction (S) of those two numbers, i.e. S=R-N. To help Donald, write a program that, given an integer S, counts the number of positive integers N that make the equation S=R-N true.
For example, if S = 9, one such number is N=12, because if we reverse the digits of N we end up with R=21, and R-N=21-12=9. Similarly, there are 7 other numbers that make the equation true, and those are: 23, 34, 45, 56, 67, 78, 89. Therefore, there are a total of 8 positive integers that make the equation S=R-N true, when the value of S is equal to 9.
Input
The first and only line contains the integer number S (1 <= S <= 1 000 000 000), the value of the subtraction as described in the problem statement.
Output
Print the number of positive integers N that make the equation S=R-N true, where R is calculated by reading the digits of N backwards.
Constraints
Time limit: 500 milliseconds
Memory limit: 256 megabytes
Examples
input 9 | output 8 |
input 10 | output 0 |
Subtasks
1) In test cases worth 6 points, (1 <= S <= 10)
2) In other test cases worth 11 points, (1 <= S <= 1 000)
3) In other test cases worth 22 points, (1 <= S <= 1 000 000)
4) To earn all 100 points, your solution must work for the input constraints presented in the “Input” section.