The program receives a set of operations with a stack. Each operation consists of either adding or removing an element from the stack. After each operation, find the smallest number among all numbers currently in the stack. Sum all such found numbers to obtain the answer. If the stack is empty after an operation, add nothing to the answer. If it is not possible to remove an element because the stack is already empty, do not perform the operation.
The input data is generated within your program. You are given parameters to generate the input sequence.
The first value is (1 \le n \le 10^6), the number of stack operations. Then four non-negative integers , , , and x_0 are given, each not exceeding .
To obtain the sequence, generate the sequence as follows:
The first number in the sequence is x_0. Each next number is calculated from the previous one by the formula:
where denotes integer division, and denotes taking the remainder after division.
If x_i \bmod 5 < 2, remove a number from the stack. Otherwise, add x_i to the stack.
Print the resulting sum.
Example 1
Example 2