#c22503. 合并数列2

合并数列2

Merging Arithmetic Sequences (II)

Problem Description

There are nn arithmetic sequences; the ii-th sequence can be written as ki×x+bik_i \times x + b_i (with x=0,1,2,…x = 0, 1, 2, \dots).

Now answer this: when all these sequences are merged in ascending order, what is the sum of the first mm numbers (a number that appears repeatedly is counted each time it appears)?

Input Format

The first line contains an integer nn.

The next nn lines each contain two integers, kik_i and bib_i.

The last line contains an integer mm.

Output Format

Output one number, the answer.

Sample Input

2
1 2
5 2
8

Sample Output

36

Sample Explanation

The two sequences are 2,3,4,5,6,7,8,…2, 3, 4, 5, 6, 7, 8, \dots and 2,7,12,…2, 7, 12, \dots respectively.

Constraints

For 100%100\% of the data: 1≤n≤1000001 \leq n \leq 100000, 1≤m≤1000001 \leq m \leq 100000, 1≤ki,bi≤10001 \leq k_i, b_i \leq 1000.