Balanced number - MarisaOJ: Marisa Online Judge

Balanced number

Time limit: 1000 ms
Memory limit: 256 MB
Given an integer x with m digits, denote di as the i-th digit from left to right of this integer. If we choose a digit at position p such that 1≤p≤m as the center of this number, the weight on the left side is: ∑i=1p−1di×(p−i) and similarly, the weight on the right side is: ∑i=p+1mdi×(i−p) A number is considered balanced if there exists a position p such that the weight on the left side is equal to the weight on the right side. Count the number of balanced integers in the range [a,b]. ### Input - A single line containing two integers a,b. ### Output - Print an integer representing the number of balanced integers in the range [a,b]. ### Constraints - 1≤a≤b≤1018 ### Example Input: 760424324 Output: 897