#P7682. [COCI 2008/2009 #5] TRESNJA

[COCI 2008/2009 #5] TRESNJA

Description

Lana lives in a happy little village. Along the main street there is a row of cherry trees. Lana noticed that each tree is numbered with consecutive integers starting from 11. After a lot of research, Lana discovered that a tree’s number uniquely determines how many cherries it has. For a given tree, split its number into groups of consecutive identical digits. For each group, multiply the unique digit in that group by the square of the group’s length. Add these values together to get the total number of cherries on the tree. For example, for the tree numbered 7774400777744007, we split the number into 44 groups: 777777, 4444, 0000, and 77. Therefore, the number of cherries on the tree numbered 7774400777744007 is 7×32+4×22+0×22+7×12=867\times 3^2+4\times 2^2+0\times2^2+7\times1^2=86.

It is time to pick cherries. The villagers agreed to pick all cherries from the trees whose numbers are in the interval [a,b][a,b]. Now you need to write a program to compute the total number of cherries that will be picked.

Input Format

The input contains only one line with two integers a,ba,b, representing the starting and ending tree numbers that can be picked.

Output Format

Output only one line with one integer, representing the total number of cherries that can be picked.

1 9
45
100 111
68
7774407 7774407
86

Hint

Constraints

For all testdata, 1ab10151\leqslant a\leqslant b\leqslant 10^{15}.

Source

This problem is from COCI 2008-2009 CONTEST 5 T5 TRESNJA, using the original testdata configuration, with a full score of 120120 points.

Translated and整理 (zhengli) provided by Eason_AC.

Translated by ChatGPT 5