Ants in a Corridor

No attempts yetTime limit3sMemory limit512 MB

Problem

A corridor is a segment of length LL. The corridor carries coordinates: its left endpoint is 00, its right endpoint is LL, and the point that divides the corridor internally in the ratio x:yx : y has coordinate xLx+y\frac{xL}{x+y}.

Whenever Gyeonggeun is bored, he puts one more ant on the corridor. Every ant on this corridor moves either left or right and covers distance 11 per second. The corridor is only wide enough for one ant. When two ants moving in opposite directions meet at a point, both reverse direction at once and keep the same speed. An ant that reaches an endpoint of the corridor also reverses direction at once and keeps the same speed. Treat an ant as a point with no size. Two ants collide only when their coordinates are exactly equal, and an ant turns around only when its coordinate is exactly 00 or exactly LL.

At time 00 seconds the corridor holds no ants. Write a program that processes QQ operations of the following two kinds.

  1. At second tt, put an ant moving right or left at coordinate xx. If this ant is the ii-th one placed, it gets number ii.
  2. Print the coordinate of ant number ii at second tt.

Input

The first line contains two positive integers LL and QQ (1L1091 \le L \le 10^9, 1Q2×1051 \le Q \le 2 \times 10^5).

Each of the next QQ lines holds one operation. Every line starts with an integer tt (0t10180 \le t \le 10^{18}), the second at which the operation happens, and a positive integer pp (1p21 \le p \le 2), the kind of the operation. The rest of the line is as follows.

  • If p=1p = 1, an integer xx (0<x<L0 < x < L) and an integer dd (d{1,1}d \in \{-1, 1\}) follow. At second tt an ant is placed at coordinate xx, moving right when d=1d = 1 and left when d=1d = -1. The input never places an ant on a coordinate that another ant occupies at that second.
  • If p=2p = 2, the number ii of the ant follows. It is at least 11 and at most the number of ants placed so far. Print the coordinate of ant number ii at second tt.

The operations come in increasing order of tt, and no two operations share the same tt.

Output

For each operation with p=2p = 2, print the coordinate of that ant on its own line. Under these constraints the coordinate at a query time is always an integer, so print it as an integer.