Tree#8366

Tree

1 second
64 megabytes
Hard

After a productive day, Serhiy decided to indulge in his favorite pastime—drawing. Naturally, he began by sketching the Main Uzhland Tree. This tree is unique: it has branches, numbered from to , arranged in a cycle. This means the branch following the first is the second, the one after the second is the third, and so on, with the branch following the -th being the first again.

Initially, each branch has a certain number of birds perched on it (some branches may have no birds at all). There are birds in total, numbered from to . Each bird has a specific weight, calculated as (a_i + b) \bmod (10^9 + 7), where and are constants, and x \bmod y denotes the remainder of divided by . All bird weights are distinct. On branch , there are initially c_i birds, such that branch has birds numbered 1, 2, \ldots, c_1, branch has birds numbered c_1 + 1, c_1 + 2, \ldots, c_1 + c_2, and so forth. It is guaranteed that c_1 + c_2 + \cdots + c_n = m.

Every second, the lightest bird from each branch with at least one bird flies to the next branch. For example, if the tree has branches, and the first branch has birds with weights \{1, 3, 5\}, the second branch has , and the third branch has \{4, 5, 6\}, then after one second, the birds' weights on the branches will be \{3, 4, 5\}, \{1, 7\}, \{2, 5, 6\} respectively. Serhiy is curious about two numbers, and . He wants to know the weight of the bird that will fly from branch number at second number .

Task

Write a program that, given the initial distribution of birds on the tree and the numbers and , determines the weight of the bird that will fly from branch number at the second number .

Input

The first line contains six integers: n \; m \; k \; t \; a \; b (1 \le n \le 10^4, 1 \le m \le 2 \cdot 10^6, 1 \le k \le n, 1 \le t \le 10^9, 1 \le a < 10^9 + 7, 0 \le b < 10^9 + 7). These represent the number of branches, the total number of birds, the numbers Serhiy is interested in, and the constants for calculating bird weights, respectively.

The second line contains integers c_1, c_2, \ldots, c_n (0 \le c_i \le m), where c_i is the initial number of birds on branch . It is guaranteed that all bird weights are unique and that c_1 + c_2 + \cdots + c_n = m.

Output

Output one integer: the weight of the bird that will fly from branch number at second number , or -1 if there is no bird on this branch before the -th second.

Examples

Example 1

Loading
Loading

Scoring

Subtask

Points

Additional Constraints

Required Subtasks

0

0

Tests from the statement

-

1

17

1 \le n, m, t \le 100

0

2

12

1 \le n \le 100, 1 \le m \le 50000, 1 \le t \le 5000

0, 1

3

18

1 \le n \le 100, 1 \le m \le 50000, 1 \le t \le 10^9

0, 1, 2

4

24

1 \le n \le 10^4, 1 \le m \le 50000, 1 \le t \le 10^9

0, 1, 2, 3

5

29

No additional constraints

0, 1, 2, 3, 4