#P8245. Sum of Digit Distances in an Interval

    ID: 21424 Type: Default 1000ms 256MiB

Sum of Digit Distances in an Interval

Sum of Digit Distances in an Interval

For two integers \(A\) and \(B\), define their distance as the sum of the absolute differences of their corresponding digits, when both are written as strings of equal length (by prepending leading zeros if necessary). Specifically, the distance is given by

\[ \operatorname{dist}(A,B)=\sum_{i=1}^{d}\left|a_i-b_i\right| \]

For example,

  • \(\operatorname{dist}(4561,3278)=|4-3|+|5-2|+|6-7|+|1-8|=12\).
  • \(\operatorname{dist}(32,5678)=|0-5|+|0-6|+|3-7|+|2-8|=21\).

Given two integers \(L\) and \(R\), compute the sum of distances for all unordered pairs of integers in the interval \([L,R]\). Since the answer can be very large, output the answer modulo \(10^9+7\).

Note: An unordered pair means that for any two numbers \(x\) and \(y\) (\(x \neq y\)) in \([L,R]\), the distance \(\operatorname{dist}(x,y)\) is counted exactly once.

inputFormat

The input consists of a single line containing two integers \(L\) and \(R\) (\(0 \le L \le R\)).

outputFormat

Output a single integer, the sum of distances over all unordered pairs of integers in the interval \([L,R]\), taken modulo \(10^9+7\).

sample

1 2
1