#include<bits/stdc++.h>
using namespace std;
stack<int>a;
stack<int>b;
int c[200000];
int main(){
b.push(0);
int n;
cin>>n;
int num=0;
for(int i=1;i<=n;i++){
int w;
cin>>w;
int k;
if(w==0){
cin>>k;
a.push(k);
if(num<a.top()){
num=a.top();
b.push(num);
}
}
else if(w==1){
if(a.top()==b.top()){
b.pop();
}
a.pop();
}else{
if(a.empty()){
cout<<0;
}else{
cout<<b.top()<<endl;
}
}
}
return 0;
}
实在不会啊!