Design a data structure similar to a stack that allows adding elements and removing the most frequent element from the stack.
The following commands are supported:
push n — add the number to the stack;
pop — remove and print the most frequent number currently in the stack. If there are multiple such numbers, remove and output the one closest to the top of the stack.
Consists of commands, one per line.
For each pop operation, print the result on a separate line.
Example 1
Example 2