题目描述
Problem Description
There is a bag containing $ N $ balls painted either red or blue. Each ball has an integer written on it.
The $ i $ -th ball has an integer $ X_i $ written on it, and its color is red if $ C_i $ is R, and blue if $ C_i $ is B.
Takahashi will repeatedly follow the procedure below to pick balls out of the bag while there are balls left in the bag:
- If there are red balls in the bag, pick the red ball with the smallest integer from the remaining red balls. Otherwise, pick the blue ball with the smallest integer from the remaining blue balls.
Determine the integers written on the balls that Takahashi picks out in each procedure.
Input Format
The input is given from the standard input in the following format:
$ N $ $ X_1 $ $ C_1 $ $ X_2 $ $ C_2 $ $ : $ $ X_N $ $ C_N $
Output Format
Output the integers written on the balls that Takahashi picks out in each procedure.
Sample Input and Output
Sample Input #1
4
10 B
6 R
2 R
4 B
Sample Output #1
2
6
4
10
Sample Input #2
2
5 B
7 B
Sample Output #2
5
7
Notes/Hints
Constraints
- $1 \leq N \leq 100$
- $1 \leq X_i \leq 10000$
- $ C_i $ is either
RorB - $X_i \neq X_j$ ( $i \neq j$ )
- $ N $ and $ X_i $ are all integers
Sample Explanation 1
While there are red balls in the bag, Takahashi picks red balls. The order of picking balls is ($ 2 $, R), ($ 6 $, R), ($ 4 $, B), ($ 10 $, B).
Sample Explanation 2
There may be only balls of one color.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分