#P8245. [COCI 2013/2014 #3] PAROVI

[COCI 2013/2014 #3] PAROVI

Problem Description

Define the distance between two integers A,BA, B as the sum of the absolute differences of the digits in each corresponding position, denoted by dist(A,B)\operatorname{dist}(A,B). In particular, if AA and BB have different numbers of digits, pad the shorter one with leading zeros. For example:

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

Now, given two integers L,RL, R, compute the sum of distances over all ordered pairs of integers within the interval [L,R][L, R]. Since the answer may be very large, take it modulo 109+7\bf 10^9+7.

Input Format

The input consists of one line containing two integers L,RL, R.

Output Format

Output one integer per line: the sum of distances over all ordered pairs of integers in [L,R][L, R], modulo 109+7\bf 10^9+7.

1 5
40
288 291
76
1000000 10000000
581093400

Hint

[Sample 2 Explanation]

All distances between integer pairs in [288,291][288,291] are:

  • $\operatorname{dist}(288,289)=\operatorname{dist}(289,288)=1$.
  • $\operatorname{dist}(288,290)=\operatorname{dist}(290,288)=9$.
  • $\operatorname{dist}(288,291)=\operatorname{dist}(291,288)=8$.
  • $\operatorname{dist}(289,290)=\operatorname{dist}(290,289)=10$.
  • $\operatorname{dist}(289,291)=\operatorname{dist}(291,289)=9$.
  • $\operatorname{dist}(290,291)=\operatorname{dist}(291,290)=1$.

Therefore, the sum of distances is 2×(1+9+8+10+9+1)=762\times (1+9+8+10+9+1)=76.

[Constraints and Limits]

For 20%20\% of the testdata, A,B104A,B\leqslant 10^4.
For 40%40\% of the testdata, A,B10100A,B\leqslant 10^{100}.
For all testdata, 1AB10500001\leqslant A\leqslant B\leqslant 10^{50000}.

[Source]

This problem comes from COCI 2013-2014 CONTEST 3 T5 PAROVI, and follows the original testdata settings, with a full score of 140140 points.

Translated and整理 provided by Eason_AC.

Translated by ChatGPT 5