Sparse Tables#621

Sparse Tables

4 seconds
128 megabytes
Medium (≈1350)

The array with integers is given. Write a program that answers the question: find the minimum on a segment between and inclusively.

Input

The first line contains three positive integers n, m~(1 \le n \le 10^5, m \le 10^7) and a_1~(1 \le a_1 < 16714589) — the number of elements in array, the number of queries and the first element in an array respectively. The second line contains two positive integers u_1 and v_1~(1 \le u_1, v_1 \le n) — the first query.

The elements a_2, a_3, ..., a_n are given with the next formula:

a_{i+1} = (23 \cdot a_i + 21563)~mod~16714589

For example, if n = 10, a_1 = 12345, we get the next array:

a = (12345, 305498, 7048017, 11694653, 1565158, 2591019, 9471233, 570265, 13137658, 1325095)

The queries are generated this way:

u_{i+1} = ((17 \cdot u_i + 751 + ans_i + 2i)~mod~n) + 1
v_{i+1} = ((13 \cdot v_i + 593 + ans_i + 5i)~mod~n) + 1

where ans_i is the answer to the -th query.

Output

Print u_m, v_m and ans_m (the values for the last query and the answer to it).

Examples

Example 1

Loading
Loading