How Many Zeros?

Time limit1sMemory limit128 MB

Summary
For each range n to m, count how many times the digit 0 appears when every integer in the range is written in decimal without leading zeros.
Level

Medium7 of 10

Topics
Math, Implementation, Number theory, Brute force
Solved
No attempts yet

Problem

Write a program that, when every integer from nn to mm is written down one by one on paper, counts how many times the digit 00 is written. Each number is written in decimal with no leading zeros. For example, writing 1010 writes the digit 00 once, and the number 00 is written as "00", which is one zero.

Input

The input consists of several test cases. Each test case is a single line containing two integers nn and mm separated by a space, with n≤mn \le m. On the last line nn is negative; do not process that line and terminate the program.

Output

For each test case, print on its own line the total number of times the digit 00 is written when listing the numbers from nn to mm.

Examples6

  1. Example 1

    Input
    10 11
    100 200
    0 500
    1234567890 2345678901
    0 4294967295
    -1 -1
    
    Expected output
    1
    22
    92
    987654304
    3825876150
    
  2. Example 2

    Input
    0 0
    -1 -1
    
    Expected output
    1
    
  3. Example 3

    Input
    1 9
    -1 -1
    
    Expected output
    0
    
  4. Example 4

    Input
    5 15
    -1 -1
    
    Expected output
    1
    
  5. Example 5

    Input
    100 100
    -1 -1
    
    Expected output
    2
    
  6. Example 6

    Input
    0 1
    -1 -1
    
    Expected output
    1