| <p> | |
| As the owner of a vast collection of fine ladders, you would like to display them to potential onlookers. | |
| You've decided to stand your <strong>N</strong> ladders up vertically, with their bases at distinct points on a horizontal number line. | |
| The <strong>i</strong>th ladder's base is at position <strong>X<sub>i</sub></strong>, and it has height <strong>H<sub>i</sub></strong>. | |
| </p> | |
| <p> | |
| The local snake population has taken an interest in your ladders. As everyone knows, snakes love nothing more than to suspend themselves horizontally above the ground! | |
| In particular, a snake of length <strong>L</strong> is able to suspend itself between the tops of two ladders | |
| <strong>a</strong> and <strong>b</strong> if and only if they meet the following conditions: | |
| </p> | |
| <ul> | |
| <li> - the ladders are exactly <strong>L</strong> units apart (|<strong>X<sub>a</sub></strong> - <strong>X<sub>b</sub></strong>| = <strong>L</strong>) </li> | |
| <li> - the ladders are of equal height (<strong>H<sub>a</sub></strong> = <strong>H<sub>b</sub></strong>) </li> | |
| <li> - there are no taller ladders in between them (there exists no ladder <strong>c</strong> such that | |
| min{<strong>X<sub>a</sub></strong>, <strong>X<sub>b</sub></strong>} < <strong>X<sub>c</sub></strong> < | |
| max{<strong>X<sub>a</sub></strong>, <strong>X<sub>b</sub></strong>} | |
| and <strong>H<sub>c</sub></strong> > <strong>H<sub>a</sub></strong>) | |
| </li> | |
| </ul> | |
| <p> | |
| A number of snakes are planning to take up residence amongst your ladders. In particular, for every position in which a snake could suspend itself | |
| (in other words, for every distinct, unordered pair of ladders <strong>a</strong> and <strong>b</strong>), | |
| one snake will move in of the appropriate length. | |
| </p> | |
| <p> | |
| You'll have no choice but to take care of these snakes, of course. To feed a snake of length <strong>L</strong>, it'll cost you <strong>L</strong><sup>2</sup> dollars daily. | |
| To prepare your budget, you'd like to calculate how many dollars you'll be spending each day on your new pets! | |
| </p> | |
| <h3>Input</h3> | |
| <p> | |
| Input begins with an integer <strong>T</strong>, the number of sets of ladders you own. | |
| For each set, there is first a line containing the integer <strong>N</strong>. | |
| Then, <strong>N</strong> lines follow, the <strong>i</strong>th of which contains two space-separated integers, | |
| <strong>X<sub>i</sub></strong> and <strong>H<sub>i</sub></strong>. | |
| </p> | |
| <h3>Output</h3> | |
| <p> | |
| For the <strong>i</strong>th set of ladders, print a line containing "Case #<strong>i</strong>: " followed by the daily feeding cost of all the snakes that move in, | |
| modulo 10<sup>9</sup> + 7. | |
| </p> | |
| <h3>Constraints</h3> | |
| <p> | |
| 1 ≤ <strong>T</strong> ≤ 50 <br /> | |
| 1 ≤ <strong>N</strong> ≤ 200,000 <br /> | |
| 0 ≤ <strong>X<sub>i</sub></strong>, <strong>H<sub>i</sub></strong> ≤ 1,000,000,000 | |
| </p> | |
| <h3>Explanation of Sample</h3> | |
| <p> | |
| In the first case, one snake will move in between your two ladders. It will have length 20, so it will cost 20<sup>2</sup> = 400 dollars a day to feed. | |
| In the third case, one snake will move in between the ladders of height 3, and another will move in between the ladders at X = 2 and X = 3. The first snake has length 3, and the second has length 1. The total cost is therefore 3<sup>2</sup> + 1<sup>2</sup> = 10. | |
| </p> | |