Input #1
7
2
5 9
0 1
3
3 4 10
0 1 2
4
1 2 3 4
0 0 1 1
5
1000000000 1000000000 1000000000 1000000000 1000000000
0 0 0 0 0
11
19 68 97 62 99 52 57 19 43 80 96
5 3 3 2 3 4 3 2 3 4 3
14
86 49 83 31 5 43 7 46 98 36 60 4 69 59
3 1 4 4 4 0 1 3 0 4 3 5 1 2
10
907139744 237517128 852012347 350549430 62876062 196019710 263351472 184393437 281593038 753973502
23 12 1 26 29 24 0 7 10 4
Output #1
1
2
4
120
8640
15552
1
For the first test case, the cost for each $P$ is as follows:
* For $P=(1,2)$, $\left \lfloor \frac{A_{1}}{2^{B_1}} \right \rfloor + \left \lfloor \frac{A_{2}}{2^{B_2}} \right \rfloor = \left \lfloor \frac{5}{1} \right \rfloor + \left \lfloor \frac{9}{2} \right \rfloor = 9$
* For $P=(2,1)$, $\left \lfloor \frac{A_{2}}{2^{B_1}} \right \rfloor + \left \lfloor \frac{A_{1}}{2^{B_2}} \right \rfloor = \left \lfloor \frac{9}{1} \right \rfloor + \left \lfloor \frac{5}{2} \right \rfloor = 11$
Thus, the minimum cost is $9$, and there is one permutation $P = (1,2)$ that achieves it.
For the second test case, $P = (1,2,3),(2,1,3)$ achieve the minimum cost of $7$.
For the third test case, $P = (1,2,3,4),(2,1,3,4),(1,2,4,3),(2,1,4,3)$ achieve the minimum cost of $6$.
For the fourth test case, all permutations of $(1,2,3,4,5)$ achieve the minimum cost of $5000000000$.