CSES - Sliding Window Xor
  • Time limit: 1.00 s
  • Memory limit: 512 MB

You are given an array of nn integers. Your task is to calculate the bitwise xor of each window of kk elements, from left to right.

In this problem the input data is large and it is created using a generator.

Input

The first line contains two integers nn and kk: the number of elements and the size of the window.

The next line contains four integers xx, aa, bb and cc: the input generator parameters. The input is generated as follows:

  • x1=xx_1=x
  • xi=(axi1+b)modcx_i=(ax_{i-1}+b) \bmod c for i=2,3,,ni=2,3,\dots,n

Output

Print the xor of all window xors.

Constraints

  • 1kn1071 \le k \le n \le 10^7
  • 0x,a,b1090 \le x, a, b \le 10^9
  • 1c1091 \le c \le 10^9

Example

Input:

8 5
3 7 1 11

Output:

0

Explanation: The input array is [3,0,1,8,2,4,7,6][3,0,1,8,2,4,7,6]. The windows are [3,0,1,8,2][3,0,1,8,2], [0,1,8,2,4][0,1,8,2,4], [1,8,2,4,7][1,8,2,4,7] and [8,2,4,7,6][8,2,4,7,6], and their xors are 88, 1515, 88 and 1515. Thus, the answer is 815815=08 \oplus 15 \oplus 8 \oplus 15 = 0.