#include <bits/stdc++.h>
using namespace std;
priority_queue<long long,vector<long long>,greater<long long>>q;
int main(){
int Q;cin>>Q;
long long sum=0;
while(Q--){
int x;cin>>x;
if(x==1) {
int t;cin>>t;
q.push(t-sum);
}
else if(x==2) {
int t;cin>>t;
sum+=t;
}
else if(x==3) {
cout<<q.top()+sum<<'\n';
q.pop();
}
}
return 0;
}