This page is still under construction.

Parts of this page are still being built. What you see may change.

Best Division

Time limit1sMemory limit256 MB

Summary
Given a pseudorandom array, find the largest K such that A can be split into K nonempty intervals of length at most L, each with XOR sum at most X.
Level

Hard8 of 10

Topics
Dynamic programming, Prefix sum, Binary search, Greedy
Solved
No attempts yet

Problem

You are given an array AA of NN integers.

You are also given two integers KK and LL.

You must divide the whole array AA into exactly KK nonempty intervals so that the length of each interval is at most LL.

The cost of an interval [S,E][S, E] is the bitwise XOR sum of all elements of AA whose indices lie in [S,E][S, E].

The score of a division is the maximum of the costs of all KK intervals in that division. You care about the best division, the one that minimizes the score. That would be too simple, so the problem is reversed.

Suppose you know the minimum score: the answer to the original problem is at most XX. Now find the maximum value of KK.

Input

The first line contains three integers NN, XX, and LL as described above (1≤L≤N≤1051 \le L \le N \le 10^5, 0≤X<268 435 4560 \le X < 268\,435\,456).

The next line contains three integers A1A_{1}, PP, and QQ (0≤A1,P,Q<268 435 4560 \le A_{1}, P, Q < 268\,435\,456). The remaining elements of the array AA are generated from these three integers as follows: for every 1<k≤N1 < k \le N, Ak=(Ak−1⋅P+Q) mod 268 435 456A_{k} = (A_{k - 1} \cdot P + Q) \bmod 268\,435\,456.

Output

Print the answer on a single line. If the answer does not exist, print 00.

Examples2

  1. Example 1

    Input
    3 1 2
    1 1 1
    
    Expected output
    2
    
  2. Example 2

    Input
    3 0 3
    1 1 1
    
    Expected output
    1