Baton Touch
Eric Barkman, the founder of the startup Aviato, has decided to leave the company and retreat to the mountains of Tibet to find inner peace. Before he goes, he must do a "baton touch" and transfer all of his critical knowledge to his successor, Jin.
Eric holds pieces of knowledge, numbered
through to
. Each piece has:
- An initial complexity
, the time it would take to transfer the knowledge immediately;
- A growth rate
, where every hour that passes before Eric begins transferring piece
increases the complexity by
.
Only one piece of knowledge can be transferred at a time, starting from . If Eric begins transferring piece
at time
, the transfer takes exactly
hours, after which
advances by that amount.
Jin is a fast learner, but he's also busy. He charges a frustration fee equal to the transfer duration of each piece (i.e. how long he has to sit and listen). Eric wants to minimise the total frustration fee across all pieces.
Input
The first line contains an integer
, the pieces of knowledge to transfer.
The next lines contain integers
and
, which represent the initial complexity and growth rate of the
th piece of knowledge.
Output
Print a single integer, the minimum total frustration fee. The answer may be very large, so return it modulo .
Example
Input 1
2
5 1
1 4
Output 1
7
Input 2
4
5 2
3 5
8 1
2 4
Output 2
108
Comments