Count subsets of the integers in [A, B] whose lexicographic order as strings matches their numerical order, modulo 1e9+7.
Medium6SortingStringDynamic programmingNo attempts yetTime limit1sMemory limit1024 MBMirek 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 x<y of the set satisfy that the string of x comes before the string of y 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 [A,B], count the subsets of {A,A+1,…,B} whose lexicographic and numerical orders agree. The empty set and every subset with a single element satisfy the condition.
The first and only line contains two integers A and B (1≤A≤B≤1018, B−A≤105).
Print one integer M on a single line, the number of subsets of {A,A+1,…,B} that satisfy the condition. The count can be very large, so print it modulo 109+7.
For A=98 and B=101 the subsets that satisfy the condition are ∅, {98}, {99}, {100}, {101}, {98,99} and {100,101}.