1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e5+7;
 4 int num[N];
 5 int len;
 6 int top;
 7 int t;
 8 deque <int> q;
 9 int main ()
10 {
11   int n;
12   while (~scanf ("%d",&n) )           {
13     while (!q.empty()) q.pop_back();
14     len=t=0;
15     top=1;
16     while (n--) {
17       int op,x;
18       scanf ("%d",&op);
19       if (op==1) {
20         scanf ("%d",&x); x-=t;
21         num[++len]=x;
22         while (!q.empty()&&num[q.back()]<=x) q.pop_back();
23         q.push_back(len);
24       }
25       else if (op==2) { // 想一想为什么要加括号 ?否则1句和2句就要连接在一块了
26         if ( (top++)==q.front() )  q.pop_front(); //1
27       }  
28       else                                        // 2
29         printf ("%d\n",num[q.front()]+t); 
30       t++;
31     }
32   }
33   return 0;
34 }