Universal Cup Judging System

Universal Cup

Süre Sınırı: 2.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

A contest cannot be without a data structure problem, even if it is only a ballon problem.

You are given a matrix $M$. Let the element in the $i$-th row and $j$-th column of the matrix be $M_{i,j}$, and let the number of rows and columns be $n$ and $m$, respectively. Initially, $n=m=1$, and $M_{1,1}=c$.

You need to perform $q$ operations, each of which belongs to one of the following three types:

  • 1 x y ($0\le x\le n$, $1\le y\le 10^9$) insert a row with value $y$ between the $x$-th row and the $(x+1)$-th row; after this operation, $n$ increases by $1$;

  • 2 x y ($0\le x\le m$, $1\le y\le 10^9$) insert a column with value $y$ between the $x$-th column and the $(x+1)$-th column; after this operation, $m$ increases by $1$;

  • 3 x y ($1\le x\le n$, $1\le y\le m$) query the value of $M_{x,y}$.

Input

The first line of input contains two integers $q,c$ ($1\le q\le 5\cdot 10^5$, $1\le c\le 10^9$).

The following $q$ lines each describe one operation.

The three integers $opt,x,y$ at the beginning of each line ($opt\in\{1,2,3\}$) have the meaning described in the statement above.

Output

For each query operation, output one line containing an integer representing the answer.

Examples

Input 1

6 1
1 0 2
3 2 1
2 1 3
1 1 4
3 2 2
3 3 2

Output 1

1
4
3

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.