#c22503. 合并数列2
合并数列2
Merging Arithmetic Sequences (II)
Problem Description
There are arithmetic sequences; the -th sequence can be written as (with ).
Now answer this: when all these sequences are merged in ascending order, what is the sum of the first numbers (a number that appears repeatedly is counted each time it appears)?
Input Format
The first line contains an integer .
The next lines each contain two integers, and .
The last line contains an integer .
Output Format
Output one number, the answer.
Sample Input
2
1 2
5 2
8
Sample Output
36
Sample Explanation
The two sequences are and respectively.
Constraints
For of the data: , , .