Under construction

Still being built. Things may change

Ants and Bitcoin

Time limit1sMemory limit512 MB

Summary
Given N ants on a stick of length L, each facing left or right, print which ant holds the Bitcoin after T seconds.
Level

Medium6 of 10

Topics
Sorting, Math, Simulation
Solved
No attempts yet

Problem

NN ants each pooled their entire fortune to buy 1 BTC of Bitcoin. Since the Bitcoin belongs to all of the ants, they take turns managing it.

The ants all stand on a stick of length LL, each facing either left or right. The leftmost endpoint of the stick is at coordinate 0, and the rightmost endpoint is at coordinate LL. Every ant stands on an integer coordinate, and no two ants share a position.

Each ant walks in the direction it faces at a speed of 1 unit per second. When an ant reaches an end of the stick, it turns around and walks back. When two ants meet (are at the same coordinate), both of them turn around. If an ant holding the Bitcoin meets another ant, it hands the Bitcoin to that ant and turns around. Turning around and handing over the Bitcoin take no time.

The figure above shows four ants, some of which hold the Bitcoin. After a short while, the situation below occurs.

As shown, the first and second ants have met, and the fourth ant has reached the end of the stick. So every ant except the third turns around.

A little later, the third and fourth ants meet. The third ant holds the Bitcoin, so it gives the Bitcoin to the fourth ant and turns around.

The ants want to know which ant holds the Bitcoin after TT seconds. Given the information about the ants, write a program that prints the number of the ant holding the Bitcoin after TT seconds. The ants are so small that they can be treated as points.

Input

The first line contains NN, LL, and TT. (1≤N≤100 0001 \le N \le 100\,000, 1≤L,T≤1 000 000 0001 \le L, T \le 1\,000\,000\,000, N+1≤LN+1 \le L)

Each of the next NN lines gives the position and direction of ants 1,2,⋯ ,N1, 2, \cdots, N in that order. The position is an integer from 1 to L−1L-1, and all positions are distinct. The direction is L (left) or R (right).

The last line contains the number of the ant holding the Bitcoin, an integer from 1 to NN.

Output

Print the number of the ant holding the Bitcoin after TT seconds.

It is guaranteed that all ants have distinct positions after TT seconds.

Examples1

  1. Example 1

    Input
    4 8 3
    1 R
    3 L
    5 R
    7 R
    3
    
    Expected output
    4