#P3754. City House Count

    ID: 17004 Type: Default 1000ms 256MiB

City House Count

City House Count

Jace is the president of Alara. Like the president of Q, he must travel to Yugo's capital by car due to wartime disruptions. Accompanying him is Tezzeret, a record keeper charged with investigating Yugo's true strength. His task is to count the number of houses in the cities along the route.

In Yugo, the cities are numbered. Tezzeret discovered a pattern: split the city number into several consecutive segments of digits (each segment is a maximal block of identical digits). For each segment, if the digit is \(d\) and the segment has length \(L\), then the contribution of that segment is given by the formula \[ d \times L^2 \] and the total number of houses in that city is the sum of the contributions of all segments. For example, consider city number 233. Its digits can be split as "2" and "33". Therefore, its house count is \[ 2 \times 1^2 + 3 \times 2^2 = 2 + 12 = 14. \]

Your task is to compute the total number of houses in all cities from city A to city Y (inclusive). Note that due to the extensive range, a direct calculation by iterating through each city may be too slow. You are required to write an efficient program to help Tezzeret complete his assignment.

inputFormat

The input consists of a single line with two integers A and Y (with 0 ≤ A ≤ Y). They represent the starting city number and the capital city number respectively.

outputFormat

Output a single integer representing the total number of houses in all cities from A to Y (inclusive).

sample

1 10
46