Hide

Problem F
Disastrous Downfall

There is a heavy rainfall over the Antique Cultural Museum, and the roof has sprung a leak! All the beautiful paintings risk destruction, if it weren’t for one brave night watchman standing in the water’s way – Klunkas Plaskocek.

To protect all of the paintings, Klunkas has brought N buckets and placed them in a long row to catch the water falling from the ceiling. Each bucket can hold exactly K drops of water. If a drop falls into a bucket which is full, the water drop will overflow to the bucket standing to the left. If that bucket is full as well, the drop will keep flowing left until there is a non-full bucket.

Klunkas needs your help to prevent the leftmost bucket overflowing. After every drop of water falls, Klunkas wants to know which bucket it ended up in, so that he can keep track of the water levels of the buckets.

Due to the very regular nature of rain, Klunkas figured that the R rain drops fall in a very nice pattern. Given constants X0,A,B, we define the sequence Xi as

Xi=(AXi1+B)modN

The bucket which the i-th rain drop falls into, is then Xi for i=1,,R. The leftmost bucket has the number 0, and the rightmost bucket has the number N1.

Input

Input consists of the space-separated integers 1N106, 1R107, 1K10, 0X0,A,B2311.

Output

If the leftmost bucket overflows, output “OVERFLOW”.

Otherwise, the output should be calculated as follows:

Let Oi be the bucket which the i:th rain drop ended up in, and let a=0.

Then, for every i from 1 to R, set a:=(53a+Oi)mod199933.

The output should then be a line with the integer a.

Sample Input 1 Sample Output 1
10 6 1 2 1 8
OVERFLOW
Sample Input 2 Sample Output 2
10 6 1 4 1 8
79732
Sample Input 3 Sample Output 3
10 20 2 8 7 3
31786
Hide

Please log in to submit a solution to this problem

Log in