Hotel Room Numbers

Interview

Time limit1sMemory limit128 MB

Summary
For each pair N and M, count the integers in [N, M] whose decimal digits are all distinct, reading cases until end of file.
Level

Easy3 of 10

Topics
Brute force, Math, Implementation
Solved
No attempts yet

Problem

Sunyoung believes that if a room number contains the same digit two or more times, misfortune will befall whoever stays in that room. So she will never use a number in which a digit repeats, such as 838 or 1004.

In 2050, Sunyoung has become the wealthiest person in Korea, and she plans to build a new hotel by the sea. To keep misfortune away from her guests, every room number must have no repeated digit.

The government granted the construction permit on the condition that each room number is at least NN and at most MM. Two different rooms cannot share the same number. What is the largest number of rooms the hotel can have? In other words, count the integers between NN and MM (inclusive) that contain no repeated digit.

Input

The input consists of several test cases. Each test case is given on one line as two integers NN and MM separated by a space. (1≤N≤M≤50001 \le N \le M \le 5000) The input continues until the end of file.

Output

For each test case, print on its own line the number of integers between NN and MM (inclusive) whose digits are all distinct (no digit repeats).

Examples3

  1. Example 1

    Input
    87 104
    989 1022
    22 25
    1234 1234
    
    Expected output
    14
    0
    3
    1
    
  2. Example 2

    Input
    1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    1 9
    
    Expected output
    9