## Kuuhaku Numbers

View as PDF

Points: 25 (partial)
Time limit: 1.4s
Memory limit: 256M

Author:
Problem type
##### Maniacal Midsummer Marathon 2014 by AL, TL, JJ

Shiro is enthralled by the latest FPS (first person shooter) game in the Eastern Federation. A lot is riding on this game, so she is planning to snipe the other player, Izuna, for a decisive victory. Shiro plans to pull this off from a kilometer away, and Izuna is in a shelter, so this requires very advanced mathematical calculations. Shiro needs a special sequence of numbers, the Kuuhaku numbers (a.k.a. KH-numbers) to accomplish her goal.

The KH-numbers have an interesting property: examining each digit of an digit KH-number in base- from left to right (most significant to least significant), there will exist a length subsequence of the digits that are nondecreasing in value. More formally: A number in the form has the sequence of digits This number is a KH-number iff there exists a sequence for , where (for ) and and (for ).

Shiro needs all the KH-numbers between and to complete her calculations. In the time you need to compute all those numbers, she is sure that she can calculate the exact numbers in her head. Therefore, Shiro only needs you to determine the number of KH-numbers that exist between and to verify her calculations.

#### Input Specification

The line of input will contain the integer .
The line of input will contain the integer .
You can assume for test cases worth of points, .

#### Output Specification

A single integer, the number of KH-numbers between and , inclusive.

#### Sample Input 1

111111
111131

#### Sample Output 1

17

#### Explanation for Sample 1

The valid KH-numbers are , , , , , , , , , , , , , , , , and .

#### Sample Input 2

2454449
2454455

#### Sample Output 2

2

#### Explanation for Sample 2

The valid KH-numbers are and .

#### Sample Input 3

1111111
1111123

#### Sample Output 3

13

#### Explanation for Sample 3

All numbers between and are KH-numbers.