Fiendish Interval

Isobel is fascinated by numbers and subsequences. She defines the subsequences of a number X any number Y obtained by removing zero or more of X's digits, but not all of them.
For example: if X = 123, then Y can be any of the 7 numbers: 1, 2, 3, 12, 13, 23 and 123.

After removing the selected digits, the number should not begin with a 0 unless it is actually 0.
For example: if X = 100, then Y can be any of the following 4 numbers: 0, 1, 10 and 100.

Isobel doesn't want to spend too much time playing with sequences as she already has a Fiendish Sudoku to solve. Therefore, she asks you to compute how many numbers in the interval [a, b) (excluding b) have the property that all their subsequences lie inside the same interval [a, b).


Two space-separated integers a and b.


The only line of output should contain the answer to Isobel's question.


  • 1 ≤ a < b ≤ 1018


1 10090
8 1006

Sponsors Gold