D. Tower of Boxes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

Cyber-shark Zubastik$$$^{\dagger}$$$ works in a warehouse and stacks boxes into a single vertical tower. The height of the tower is unlimited, but the shark can only remove and place the top box on the tower. There is also a buffer nearby — a free area where boxes can be temporarily held (any number of boxes can be in the buffer).

Boxes are numbered in the order they arrive, starting from $$$1$$$. For each box, the moment in time $$$t_j$$$ when it needs to be extracted from the warehouse is known.

During the work, there are two types of events:

  • + t — a new box has arrived, which needs to be extracted at time $$$t$$$ $$$(1 \le t \le T)$$$. All values of $$$t$$$ are distinct.
  • - j — the moment $$$t_j$$$ has arrived, and box number $$$j$$$ needs to be extracted.

Actions. During the processing of an event, the shark can perform the following operations:

  • 1 j — place box $$$j$$$ on top of the tower (allowed only if box $$$j$$$ is in the buffer).
  • 2 j — place box $$$j$$$ in the buffer (allowed only if box $$$j$$$ is on top of the tower).

Rules for processing events.

  • At the event + t, the new box is immediately placed in the buffer. By the end of processing this event, the buffer must be empty.
  • At the event - j, by the end of processing this event, there must be exactly one box left in the buffer — box $$$j$$$. After this, box $$$j$$$ is considered extracted and removed from the system.

Your task is to output a set of operations for each event that correctly processes that event.

$$$^{\dagger}$$$ see fig.

Cyber-shark Zubastik
Input

The first line contains $$$T$$$ — the number of moments in time to consider.

In the $$$i$$$-th of the subsequent $$$T$$$ lines, the description of the next event occurring at time $$$i$$$ is given in the following format:

  • + t — a new box has arrived, which needs to be removed at time $$$t$$$ $$$(1 \le t \le T)$$$. (Boxes are numbered in the order of arrival). After processing this event, the buffer must be empty.
  • - j — it is time to extract box $$$j$$$. After processing this event, box $$$j$$$ must remain in the buffer.
Output

For each event, you need to output a sequence of operations that will process it.

First, an integer $$$K$$$ — the number of operations.

Then a list of $$$K$$$ operations — for each, two numbers:

  • The type of operation (1 or 2).
  • Then the number of the box with which the operation is performed.

The total number of operations output across all events must not exceed $$$10^6$$$. If this limit is violated, the solution will receive a verdict of Wrong Answer.

Interaction

First, your program must read an integer $$$T$$$ — the number of events.

Then for each $$$i = 1,2,\dots,T$$$, the interactor outputs a line with the description of the event occurring at time $$$i$$$:

  • + t — a new box has arrived, which needs to be extracted at time $$$t$$$ $$$(1 \le t \le T)$$$. The box receives the next sequential number. By the end of processing the event, the buffer must be empty.
  • - j — box $$$j$$$ needs to be extracted. By the end of processing this event, exactly one box $$$j$$$ must remain in the buffer.

After receiving the next event, your program must output the response for it in the following format:

  • In the first line, an integer $$$K$$$ — the number of operations to process the current event;
  • Then $$$K$$$ lines, each with two integers: the type of operation ($$$1$$$ or $$$2$$$) and the number of box $$$j$$$.

To receive the next event, you must output a correct response for the current event and end the line with a newline character.

After outputting the response, be sure to flush the output buffer:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python.

Note that for faster output, it is advisable to call flush (or endl) after outputting all $$$K$$$ operations, rather than after each operation.

The interactor in this problem is non-adaptive: within a single test, the sequence of events is fixed and does not change based on your responses.

Scoring

In this problem, there are two types of tests.

The first type of test — an array [1, 1, 2, 2, ..., N, N] is generated and shuffled randomly, resulting in an array $$$[a_1, a_2, \dots, a_T]$$$ of size $$$T$$$, where $$$T = 2N$$$. A box is added at time $$$t_1$$$ and taken out at time $$$t_2$$$, if $$$t_1 \lt t_2$$$ and $$$a[t_1] = a[t_2]$$$.

The second type of test — it is guaranteed that the boxes are taken out in the same order they are added.

For each value of $$$N$$$ (the number of boxes), one test of each type is generated.

GroupTestsValues of $$$N$$$PointsCumulative SumDependencies
11-2Tests from the statement0 per test0-
23-10100, 200, 330, 4201 per test8-
311-18480, 720, 820, 10801 per test161
419-261240, 1420, 1630, 18701 per test241-2
527-302150, 24701 per test281-3
531-342840, 32602 per test361-3
635-423740, 4300, 4940, 56802 per test521-4
743-506530, 7500, 8620, 99102 per test681-5
851-5811390, 13090, 15050, 173002 per test841-6
959-6617500, 18000, 18500, 190002 per test1001-7
Examples
Input
4
+ 3
+ 4
- 1
- 2
Output
1
1 1
3
2 1
1 2
1 1
1
2 1
1
2 2
Input
8
+ 8
+ 3
- 2
+ 7
+ 6
- 4
- 3
- 1
Output
1
1 1
1
1 2
1
2 2
1
1 3
1
1 4
1
2 4
1
2 3
1
2 1