Lexicographic Sorting
Time limit1sMemory limit1024 MB
Count subsets of the integers in [A, B] whose lexicographic order as strings matches their numerical order, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Sorting, String, Dynamic programming
- Solved
- No attempts yet
Problem
Mirek keeps several files of integers and had to sort the integers in each file in ascending order. He found a command line tool whose name was easy to guess and ran it. The tool treated every integer as a string and sorted the numbers lexicographically. Even so, the files came out in ascending numerical order, and that surprised him.
Say that the lexicographic and numerical orders of a set of integers agree when sorting the decimal representations of its elements as strings gives the same listing as sorting the elements by value. Equivalently, every two elements of the set satisfy that the string of comes before the string of lexicographically.
Strings are compared one character at a time, and when one string is a prefix of the other, the shorter one comes first. So 1 comes before 10, while 98 comes after 100.
Given the range , count the subsets of whose lexicographic and numerical orders agree. The empty set and every subset with a single element satisfy the condition.
Input
The first and only line contains two integers and (, ).
Output
Print one integer on a single line, the number of subsets of that satisfy the condition. The count can be very large, so print it modulo .
Hint
For and the subsets that satisfy the condition are , , , , , and .