You have discovered a new type of fluid! You're extra excited because it comes in many different colours (which means more marketing potential, of course).
It can be shown that these fluids can be mainly described by two characteristics: its volume and its colour.
While messing around performing rigorous experiments, you have discovered that when you place two of these fluids together, one on top of the other, sometimes they will swap places!
In particular, you discover that if you place a fluid of volume
As you are very interested in this process, you've decided to place a bunch of these fluids in a jar and see the result. Because of how the swapping process works, every time you place a new fluid into the jar, that fluid will keep exchanging places with the fluid directly below it in the jar, as long as it satisfies the swapping condition described above.
However, as doing this manually is incredibly laborious and you're very lazy busy, you've decided to create a program to simulate the results instead!
Input Specification
The first line will contain three integers,
The next
The next
INSERT v c
means to place a fluid of volumev
and colourc
at the top of the jar.K-TH k
means to output the fluid's (counting from the bottom of the jar, starting from 1) characteristics (its volume and colour) separated by a single space.
Fluids do not combine! (Even if they are adjacent and have the same colour.)
Output Specification
For every query of type K-TH
, output that fluid's volume and colour separated by a space on a new line.
Constraints
For all subtasks:
It is guaranteed that K-TH
queries will refer to a valid index in the jar (i.e., greater than 1 and less than equal to the current number of fluids present in the jar).
Subtask 1 [10%]
Subtask 2 [90%]
No additional constraints.
Sample Input 1
5 5 7
15 2
20 12
7 16
7 12
20 3
K-TH 2
INSERT 1 10
INSERT 8 1
INSERT 9 1
K-TH 6
Sample Output 1
20 3
7 12
Explanation of Sample Output 1
For this sample input,
We start by placing the fluid
We then place the third fluid,
We then place the fourth fluid,
Finally, for the fifth fluid,
Fluid Directly Below | Will Swap Places? | |
---|---|---|
Yes | ||
Yes | ||
Yes | ||
No |
Thus, for the first query, the second fluid from the bottom is
1 10
7 16
7 12
20 12
9 1
8 1
20 3
15 2
So the fluid
Sample Input 2
10 10 25
41 12
35 7
18 49
25 47
19 47
28 25
4 6
8 29
30 24
35 26
INSERT 22 43
INSERT 2 19
INSERT 20 42
K-TH 7
K-TH 2
K-TH 10
K-TH 3
K-TH 11
INSERT 10 30
K-TH 8
Sample Output 2
25 47
41 12
19 47
35 26
18 49
22 43
Comments