#P3107. Interesting Odometer Miles

    ID: 16365 Type: Default 1000ms 256MiB

Interesting Odometer Miles

Interesting Odometer Miles

Farmer John's cows are on a road trip! The odometer on their car displays an integer mileage value. It starts at X miles (100 ≤ X ≤ 1018) and ends at Y miles (X ≤ Y ≤ 1018). Whenever the odometer shows an interesting number (including at the start and end of the trip) the cows will moo.

A number is said to be interesting if, when you look at all its digits (ignoring any leading zeros), at least half of these digits are the same. In other words, if a number has L digits then it is interesting if there exists a digit d such that its frequency is at least \(\lceil L/2 \rceil\). For example, the numbers 3223 and 110 are interesting, whereas 97791 and 123 are not.

Your task is to count how many times the cows will moo during the trip, i.e. count the number of interesting mileage values in the interval [X, Y].

Note: All formulas are shown in LaTeX. The condition for a number with L digits to be interesting is that there exists a digit d such that its frequency is at least \(\lceil L/2 \rceil\).

inputFormat

The input consists of two space‐separated integers X and Y on a single line.

\(100 \le X \le Y \le 10^{18}\).

outputFormat

Output a single integer, the number of interesting odometer readings in the range [X, Y].

sample

100 200
29