#P1026. Problem 1. Lazy Cow

Problem 1. Lazy Cow

当前没有测试数据。

一、Problem Name

Lazy Cow

二、Problem Description

Bessie is hard at work preparing test cases for the USA Cowmputing Olympiad February contest. Each minute, she can choose to not prepare any tests, expending no energy; or expend 3a13^{a - 1} energy preparing aa test cases, for some positive integer aa.

Farmer John has DD (1D21051\leq D\leq2\cdot10^5) demands. For the iith demand, he tells Bessie that within the first mim_i minutes, she needs to have prepared at least bib_i test cases in total (1mi1061\leq m_i\leq10^6, 1bi10121\leq b_i\leq10^{12}).

Let eie_i be the smallest amount of energy Bessie needs to spend to satisfy the first ii demands. Print e1,,eDe_1,\cdots,e_D modulo 109+710^9 + 7.

三、Input Format (input arrives from the terminal / stdin)

  1. The first line contains DD. The iith of the next DD lines contains two space - separated integers mim_i and bib_i.

四、Output Format (print output to the终端 / stdout)

Output DD lines, the iith containing eimod109+7e_i\bmod10^9 + 7.

五、Sample Input and Output

Sample Input 1

4
5 11
6 10
10 15
10 30

Sample Output 1

21
21
25
90

Explanation: For the first test case, when i=1i = 1: If Bessie creates [2,3,2,2,2][2,3,2,2,2] test cases on the first 5 days, respectively, she would have expended 31+32+31+31+31=213^1 + 3^2 + 3^1 + 3^1 + 3^1 = 21 units of energy and created 11 test cases by the end of day 5. When i=2i = 2: Bessie can follow the above strategy to ensure 11 test cases are created by the end of day 5, and this will automatically satisfy the second demand. When i=3i = 3: If Bessie creates [2,3,2,2,2,0,1,1,1,1][2,3,2,2,2,0,1,1,1,1] test cases on the first 10 days, respectively, she would have expended 25 units of energy and satisfied all demands. It can be shown that she cannot expend less energy. When i=4i = 4: If Bessie creates 3 test cases on each of the first 10 days she would have expended 3210=903^2\cdot10 = 90 units of energy and satisfied all demands. For each ii, it can be shown that Bessie cannot satisfy the first ii demands using less energy.

Sample Input 2

2
100 5
100 1000000000000

Sample Output 2

5
627323485

Sample Input 3

20
303590 482848034083
180190 112716918480
312298 258438719980
671877 605558355401
662137 440411075067
257593 261569032231
766172 268433874550
8114 905639446594
209577 11155741818
227183 874665904430
896141 55422874585
728247 456681845046
193800 632739601224
443005 623200306681
330325 955479269245
377303 177279745225
880246 22559233849
58084 155169139314
813702 758370488574
929760 785245728062

Sample Output 3

108753959
108753959
108753959
148189797
148189797
148189797
148189797
32884410
32884410
32884410
32884410
32884410
32884410
32884410
3883759
3883759
3883759
3883759
3883759
3883759

六、Scoring Rules

  1. Inputs 4 - 5: D100D\leq100 and mi100m_i\leq100 for all ii.
  2. Inputs 6 - 8: D3000D\leq3000.
  3. Inputs 9 - 20: No additional constraints.

Problem credits: Brandon Wang and Claire Zhang.