— Calm yourselves a little...
We have a ball which lies on the axis, initially placed at the coordinate. We also have sets of walls which lie on the axis. Each set is described as a tuple where:
- indicates the direction in which the walls are placed, which can either be
L
(left) orR
(right) - if
L
, then the walls in the set are placed at , , , ..., - if
R
, then the walls in the set are placed at , , , ...,
Note that through the nature of these informations, there can be multiple walls placed at the same coordinate.
At time the ball starts moving to the right with a constant speed of one unit per second. When the ball hits a wall, the wall is automatically destroyed and the ball reverses its direction. If there are multiple walls situated at the same coordinate, only one of the walls is destroyed.
Task
You are given queries. For each query you are given an integer . Output the coordinate of the ball after seconds.
Input data
The first line of input will contain the integers and , separated by one space.
The next lines contain three space-separated integers, , and , describing how the walls are placed.
The next lines contain an integer, , describing a query.
Output data
Output lines, the −th line should contain the answer for −th query.
Constraints and clarifications
L
R
# | Points | Constraints |
---|---|---|
0 | 0 | Examples |
1 | 13 | |
2 | 8 | |
3 | 16 | |
4 | 10 | |
5 | 11 | |
6 | 9 | Let be the sum of all in the input. |
7 | 33 | No additional constraints |
Example
stdin
3 12
R 3 2
R 6 1
L 3 2
0
1
2
3
4
5
6
7
17
18
19
200
stdout
0
1
2
3
2
1
0
-1
5
6
5
-152