Editorial
Let . If has decimal digits, then
For , is not divisible by , so we can divide using its modular inverse. Let be the geometric-series part of this expression modulo .
Let be the number of digits in . The product over all pairs with left endpoint is
Scan from right to left and maintain a suffix product for each digit count . First multiply the answer by . Then multiply every by . This order excludes the pair .
Precompute the inverses of . To compute every , calculate once and then obtain by successive multiplication. Each case takes time and space.
Proof
Immediately before processing , is exactly the product of over all . Initially there are no elements to the right, so every . After multiplying the contribution of into the answer, multiplying by preserves the invariant for the next index.
Each pair contributes one factor of and one factor of when its left endpoint is processed. It is not included at any other step. Thus, the final answer is the required product over all pairs.
In subtask 1, the repeated number can be built directly. In subtask 2, evaluate the geometric-series formula for every pair. In subtask 3, every value has one digit, so only one suffix product is needed. For the full constraints, maintain one suffix product for each of the ten possible digit counts.
Solution written by GPT5