AT_arc224_d [ARC224D] Angst for All Pairs
Description
There are $ N $ cards, numbered $ 1 $ through $ N $ . Initially, nothing is written on any of the cards.
You can write zero or more positive integers on each card.
The cost of writing a positive integer $ k $ once is equal to the number of digits in the decimal representation of $ k $ .
Determine whether it is possible to satisfy the following condition. If it is possible, output the minimum total cost required; if it is not possible, output $ -1 $ .
- For every pair of positive integers $ (x,y) $ satisfying $ 1 \leq x < y \leq K $ , there exists a card containing exactly one of $ x $ and $ y $ .
$ T $ test cases are given; solve each of them.
Input Format
The input is given from Standard Input in the following format, where $ \mathrm{case}_i $ denotes the $ i $ -th test case:
> $ T $ $ \mathrm{case}_1 $ $ \mathrm{case}_2 $ $ \vdots $ $ \mathrm{case}_T $
Each test case is given in the following format:
> $ N $ $ K $
Output Format
Output $ T $ lines. The $ i $ -th line should contain the answer for the $ i $ -th test case.
Explanation/Hint
### Sample Explanation 1
This input contains four test cases.
For the first test case, writing as follows satisfies the condition with a total cost of $ 5 $ .
- Write $ 1, 5 $ on card $ 1 $ .
- Write $ 2, 5 $ on card $ 2 $ .
- Write $ 3 $ on card $ 3 $ .
For the second test case, the minimum total cost required to satisfy the condition is $ 39 $ .
For the third test case, it is impossible to satisfy the condition, so output $ -1 $ .
For the fourth test case, the minimum total cost required to satisfy the condition is $ 17655598 $ .
### Constraints
- $ 1 \leq T \leq 10^5 $
- $ 1 \leq N \leq 10^6 $
- $ 2 \leq K \leq 10^6 $
- The sum of $ N $ in each input is at most $ 10^6 $ .
- The sum of $ K $ in each input is at most $ 10^6 $ .
- All input values are integers.