Text Editor#8369

Text Editor

1 second
64 megabytes
Hard

You have been hired by a large software company to develop a powerful text editor. A modern text editor offers many features, but its development can be streamlined by a modular approach: all functionality can be divided into separate functions and libraries, each handled by a different team or even a single programmer.

The text in the editor is formed as follows: the user adds one word at a time, either to the end or the beginning of the text, separating each word from adjacent words by a space. A single line in the editor window can contain no more than characters, including spaces. The editor uses standard word wrap: the first word that does not fit on the current line is moved to the next line. If two consecutive words are split by this wrapping, the space between them is omitted.

Input

The first line contains two natural numbers and (1 \leq L, N \leq 10^5) — the maximum number of characters per line and the total number of editor operations, respectively.

Each of the next lines describes an operation, which is one of three types:

  1. Add a word of length (1 \leq w \leq L) to the end of the text.

  2. Add a word of length (1 \leq w \leq L) to the beginning of the text.

  3. Query the number of lines currently occupied by the text.

For operations of type 1 or 2, the line contains two numbers: the operation type and the length . For operation 3, the line contains only the operation type. The first operation in the input will always be of type 1 or 2 (interpreted identically: adding the first word to an empty text). There is at least one operation of type 3 in the input.

Output

For each operation of type 3 in the input, output the current number of lines in the text at the time of the query, each on a separate line.

Examples

Example 1

Loading
Loading

Scoring

The problem is divided into subtasks with the following constraints:

Subtask

Points

Additional constraints

Requires

0

0

Sample tests

—

1

8

L \leq 2

—

2

8

The total length of all entered words does not exceed

—

3

7

N \leq 1000 and no operations of type 2

—

4

14

No operations of type 2

3

5

7

N \leq 1000 and no operations of type 1

—

6

16

No operations of type 1

5

7

7

N \leq 1000

3, 5

8

33

No additional constraints

0, 1, 2, 3, 4, 5, 6, 7