JDCC '16 Contest 5 P3 - Careless Sums

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Nicole's twin brother Andrew is much less stoked about learning how to add. Andrew is very lazy, so he dislikes the amount of effort required to add numbers together, especially when carrying is involved. Hence, Andrew has decided to use his sister's simplified adding algorithm for numbers rather than words.

For two numbers, he will first add their one's digits together. If the sum is higher than 10, he subtracts 10. He makes the resulting sum the one's digit of the sum. He proceeds to do the same for the ten's place, hundred's place, etc. For example:

  123
+ 987
= 000

Note that no carrying occurs. Equipped with his fast addition algorithm, Andrew is able to breeze through his homework. Looking for a challenge, he has decided to find sums of ranges of numbers. That is, for two numbers N, M, he finds the sum of all the numbers between N and M inclusive.

After practicing on all the numbers in the house, Andrew has challenged you to a race.

Can you, with your all-powerful computer, beat Andrew in summing a range of numbers?

Input

Each test case contains two integers N, M (1 \le N \le M \le 10^{18}).

For 40\% of the cases, M \le 10 000.

Output

For each test case, output, on one line, the sum of the numbers between N and M inclusive according to Andrew's addition algorithm.

Sample Input

11 19

Sample Output

95

Sample Input

41 100

Sample Output

160

Comments

There are no comments at the moment.