"Why don't you write some background story for this boring data structure problem?""Because it's too boring..."There's a queue(not the original queue one may refer to as a data structure, here a double-ended queue, to be more precise) that is initially empty. Then, there are infinite elements numbered $1,2,\dots$, entering the queue in the order of their numbers(i.e., the first element to enter the queue is numbered $1$, the second, $2$ et cetera). If an element leaves the queue, it will not enter the queue anymore.
Now there are $q$ operations, each in one of the following forms:
- Let the next element enter the left end of the queue.
- Let the next element enter the right end of the queue.
- Let the element numbered $x$ leave the queue.
- Ask the number of the element in the middle of the queue. (If there are $m$ elements in the queue currently, you should output the number of the element that is the $\lceil \frac{m+1}{2} \rceil$th from the left).