#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <string> #include <climits> #include <string.h> #include <algorithm> using namespace std; #define fast ios::sync_with_stdio(false);cin.tie(0); cout.tie(0) #define pb push_back #define sz(s) (int)s.size() #define all(x) (x).begin(), (x).end() typedef long long ll; typedef pair<ll, ll> pll; //const ll N = (ll)1e6 + 7; //const ll inf = 1e16; int main(){ fast; int n,type,x,idx=0,add=0; cin>>n; priority_queue<pll> pq; for(int i=1;i<=n;i++){ cin>>type; if(type==1){ cin>>x; pq.push({x,++add}); }else if(type==2){ idx++; }else{ while(pq.top().second<=idx) pq.pop(); cout<<pq.top().first<<endl; } } return 0; }