Equanimous
Time limit2sMemory limit256 MB
For each query (l, r), the task sums the integers m in [l, r] grouped by f(m), the minimal absolute signed-digit sum, for values 0 to 9, modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Alice, Bob, and Eve play a game on craft paper. Each time Eve names a natural number, Alice and Bob write that number in decimal on their own paper, put a plus or minus sign before each digit, and evaluate the expression they wrote. The player with the smaller absolute value wins. If the absolute values are equal, the game is a draw and they play one more round.
If they are smart, the game never ends. So they turn to the optimal solution of the puzzle. Let be the minimal absolute value that can be built from . Find for .
They also set a puzzle for you. For several queries , find the sum of all integers with and , for each . Report the answers modulo .
Input
The first line contains one integer (), the number of queries. Each of the next lines contains two integers and ().
Output
For each query, print one line with ten space-separated integers. The -th integer, counting from to , is the sum of all with and , modulo .
Hint
The digits of are , which can build the expression . Its value and absolute value are both .
The digits of are , which can build the expression . Its value is and its absolute value is .