Given a growing set of stored image indices, find the longest run of consecutive unmarked indices below each query length w_j.
Medium6ArraySortingMathImplementationNo attempts yetTime limit2sMemory limit512 MBEarl has just finished an extremely efficient encryption algorithm that shrinks video files. A video can be seen as a series of images placed in order.

The simplest method stores every image on its own. Earl's algorithm instead stores only the difference between successive images. One difference fits in a single 32-bit integer, and such a value is called a transition integer. Given the unencrypted first image and all of the transition integers, you can recreate the video exactly.
The problem is that computing a transition integer is lossy. A 32-bit integer is only an approximation of the real difference, so errors happen and an image can be displayed incorrectly. Each single transition works correctly with very high probability, but the probability of playing a whole video with no error is quite low. Errors also pile up, because the next difference is applied on top of an image that was already generated incorrectly.
To limit this, the algorithm stores a whole subset of the images in unencrypted form instead of the first image alone. At each transition the algorithm checks whether the true next image is stored. If it is, that stored image is displayed. If it is not, the algorithm uses the transition integer to generate the next image.
The badness of a video is the largest number of transition integers used in a row. Earl's algorithm handles every video with at most L images. Given the number of images in each video of a collection and the set of images Earl stores unencrypted, compute the badness of every video.
The input contains a single test case.
The first line contains six integers separated by spaces: k (1≤k≤100), n (1≤n≤105), L (1≤L≤109), a (0≤a≤L), b (0≤b≤L) and g1 (0≤g1≤L). Set g0=0 and define the remaining terms by
gi=(a⋅gi−1+b)mod(L+1)(2≤i≤n)
Each of the next k lines contains one integer. The jth of them holds wj (1≤wj≤L), the number of images in the jth video when it is stored uncompressed. The images of the jth video are numbered 0 through wj−1, and the set of images Earl stores unencrypted is
{gi:0≤i≤n}∩{0,1,…,wj−1}
Because g0=0, image 0 is always stored unencrypted. The videos are given in increasing order of wj.
Print the badness of each video on its own line, in the order the videos are given.
In the first example the images stored unencrypted are 0, 2, 4, 6, 8 and 10. The video of length 1 needs no transition integer at all, so its badness is 0. The video of length 3 uses a transition integer only to go from image 0 to image 1. The video of length 7 uses one transition integer when going from image 0 to 1, from 2 to 3 and from 4 to 5, but never two in a row, so its badness is 1. The video of length 14 has to generate images 11, 12 and 13 with consecutive transition integers, so its badness is 3.