Problem E
Stogovi
Mirko is playing with stacks. In the beginning of the game,
he has an empty stack denoted with number
-
place number
on top of the new stack -
remove the number from the top of the new stack
-
choose another stack denoted with
and count how many different numbers exist that are in the new stack and in the stack denoted with
The newly created stack is denoted with
Mirko doesn’t like to work with stacks so he wants you to write a program that will do it for him. For each operation of type 2 output the number removed from stack and for each operation of type 3 count the required numbers and output how many of them there are.
Input
The first line of input contains the integer
The steps of the game are chronologically denoted with the
first
The
-
a v for an operation of type 1.
-
b v for an operation of type 2.
-
c v w for an operation of type 3.
The first character in the line denotes the type of
operation and the following one or two denote the accompanying
stack labels that will always be integers from the interval
For each operation of type 2, the stack we are removing the element from will not be empty.
Output
For each operation type 2 or 3 output the required number, each in their own line, in the order the operations were given in the input.
Sample Input 1 | Sample Output 1 |
---|---|
5 a 0 a 1 b 2 c 2 3 b 4 |
2 1 2 |
Sample Input 2 | Sample Output 2 |
---|---|
11 a 0 a 1 a 2 a 3 a 2 c 4 5 a 5 a 6 c 8 7 b 8 b 8 |
2 2 8 8 |