RMQ#5472

RMQ

2 seconds
256 megabytes
Easy

You are given an array of integers and queries. Each query asks for the minimum value on a segment with endpoints l_i and r_i.

Input

The input consists of test cases. Each test case includes four integers: , , , and (1 \le N \le 25000, 1 \le A, B \le 10^9). Here, is the size of the array, and is the number of queries. The array and queries are generated as follows:

Write the sequence of numbers A \cdot 1 + B,\; A \cdot 2 + B,\; \ldots,\; A \cdot (N + 2 \cdot M) + B modulo 2^{32}. The first numbers in this sequence form the elements of the array. The numbers from N + 1 to N + 2 \cdot M, taken modulo , form pairs of numbers l_i - 1 and r_i - 1, which are used as the query endpoints.

The input ends with a line containing .

The sum of over all test cases does not exceed 10^9, and the sum of over all test cases does not exceed .

Output

For each test case, print the sum of the results of all queries on a separate line.

Examples

Example 1

Loading
Loading

Note

Array: 1574545889\ 2529925775\ 3485305661\ 145718251\ 1101098137\ 2056478023\ 3011857909\ 3967237795\ 627650385\ 1583030271

Queries: