Help The Headmaster

3.8

5 votes
Easy
Problem

Important Notice - Apr 7 11:45 PM:

The time limit for the question "Help the Headmaster" has been revised. Everyone is requested to rerun their earlier submitted code if it was partially submitted earlier.

 

Summer vacation starts at Hogwarts and in absense of students Headmaster Dumbledore was getting bored. So, he decided to go to his hometown, mainly wizarding village of Mould-on-the-Wold. There he was greeted by a group of children who recognised him by his famous beard and robe. They were keen to see a magic trick by the greatest magician himself.

Dumbledore agreed to their wish and shows them a magic trick in which he asks them for any natural number and then he converts that number into another number with his Elder wand. The new number would contain all the digits of the previous number in non-decreasing order but with all zeros removed.

For example, if the number is 57040, it would be converted into the number 457.

The children are not that impressed as it was too simple. They decided to make it a little bit more challenging.

They give him a range of natural numbers from L to R (both inclusive), on which he is going to do magic and determine how many distinct new numbers are going to be obtained by him by the end.

Help the Headmaster to prove his might to these young wizards.

Input:

In the first and only string, the numbers L and R are given – the boundaries of the range (1 ≤ L ≤ R ≤ 1018).

Output:

Output the sole number – the answer for the problem.

 

Examples:

Input 1-

1 10

Output 1-

9

 In the first sample case, the outputs are the numbers from 1 to 9. Note that 10 and 1 have the same output – the number 1.

Input 2-

40 57

Output 2-

17

 In the second sample case, each number has a unique output, except for the pair 45, 54. The answer to this sample case is going to be (57 - 40 + 1) - 1 = 17.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Outputs are the numbers from 1 to 9. Note that 10 and 1 have the same output – the number 1.

Editor Image

?