#include <bits/stdc++.h>
using namespace std;
typedef multiset<int>::iterator It;
multiset<int> s;
int q;
inline void solve(void)
{
cin >> q;
s.insert(INT_MIN);
s.insert(INT_MAX);
for (int i = 1; i <= q; i++)
{
int op, x;
cin >> op >> x;
if (op == 1)
{
auto it = s.lower_bound(x);
int order = 0;
for (auto i = s.begin(); i != it; i++, order++)
;
cout << order << '\n';
}
else if (op == 2)
{
int order = 0;
for (auto k : s)
{
if (order++ == x)
{
cout << k << '\n';
break;
}
}
}
else if (op == 3)
{
cout << *(--s.lower_bound(x)) << '\n';
}
else if (op == 4)
{
cout << *(s.upper_bound(x)) << '\n';
}
else if (op == 5)
{
s.insert(x);
}
}
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}