#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
multiset<int> st;
signed main() {
int n;
cin >> n;
int op, x;
while (n--) {
scanf("%d%d",&op,&x);
if (op == 1) {
st.insert(x);
} else if (op == 2) {
auto it = st.find(x);
st.erase(it);
} else if (op == 3) {
cout << distance(st.begin(), st.lower_bound(x)) + 1 << endl;
} else if (op == 4) {
auto it = st.begin();
advance(it, x - 1);
printf("%d\n",*it);
} else if (op == 5) {
auto it = st.lower_bound(x);
it--;
printf("%d\n",*it);
} else if (op == 6) {
auto it = st.upper_bound(x);
printf("%d\n",*it);
}
}
}