Under construction

Still being built. Things may change

Treasures

Interview

Time limit2sMemory limit32 MB

Summary
Given n piles generated by a recurrence, find the shortest consecutive block whose sum is at least the sum of all other piles.
Level

Medium5 of 10

Topics
Sliding window, Two pointers, Array
Solved
No attempts yet

Problem

And that is what became of me, Jim. All because in my youth I went to the graveyard to play heads or tails!

Ben Gunn

Being the only person on the island, Ben Gunn lost his mind. He split the treasure in the cave into nn piles and laid them out in a row. Now he keeps seeing Captain Flint, who wants to take part of the treasure from him.

Since Flint is only a hallucination, his demands are unusual. He wants to take kk piles that lie consecutively in the row, so that the total value of these piles is at least the total value of all the other treasure. The number of piles must be as small as possible.

Ben Gunn cannot say what the value of each pile is. He only remembers the values of the first two piles, and that he computed the value of the ii-th pile by the formula

(a⋅ti−2+b⋅ti−1+c)mod  d(a \cdot t_{i-2} + b \cdot t_{i-1} + c) \mod d

where aa, bb, cc, and dd are constants that Nick Allardyce gave him, and ti−1t_{i-1} and ti−2t_{i-2} are the values of the (i−1)(i-1)-th and (i−2)(i-2)-th piles.

Help Ben Gunn give part of his treasure to Flint.

Input

The first line contains nn (2≤n≤1072 \le n \le 10^7), the number of piles. The second line contains xx and yy (0≤x,y≤1090 \le x,y \le 10^9), the values of the first two piles. The third line contains aa, bb, cc, and dd (0≤a,b,c≤109,1≤d≤1090 \le a, b, c \le 10^9, 1 \le d \le 10^9).

Output

Print the numbers of the first and the last piles Flint should take. If there are several answers, print any of them.

Hint

Note that memory is limited in this problem.

Examples1

  1. Example 1

    Input
    10
    1 2
    0 1 1 11
    
    Expected output
    6 9