Due to some infrastructure limits the memory limit is set to 13 MB. Note that this should correspond to an actual memory limit of only 1 MB. If your solution allocates more than 1 MB of memory, it may exceed the memory limit.
You are given an array X[0..n1] of integers.
For each i between 0 and n1, inclusive, the radius of element i is the largest k with the following properties:
 Both ik and i+k are valid indices into the array. That is, ik >= 0 and i+k < n.
 The value X[i] is the strict maximum among the values X[ik], X[ik+1], ..., X[i+k]. (Here, "strict" means that the values at all other indices must be strictly smaller.)
For example, in the array X = {4,4,4,4,4} the radius of each element is 0, and in the array X = {10,20,30,20} the radius of element 2 (0based index) is 1.
Your task is to find the radius of each element of X and to compute the sum of all those radii.
Right now, this seems like a fairly standard problem.
Here's the catch: the memory limit in this problem is really small.
So small that you cannot even store the array X into memory.
You are given the int n and the longs x0, a, and b.
Use the following pseudocode to generate the array X:
X[0] = x0
for i = 1 to n1:
X[i] = ((X[i1] XOR a) + b) AND ((2^50)  1)
In the above pseudocode, XOR and AND are the standard operators "bitwise xor" and "bitwise and".
Return the sum of radii of all elements of X, modulo 1,000,000,007.
