#include <bits/stdc++.h>
using namespace std;
multiset<int> m;
int main()
{
int q, p = 0;
cin >> q;
int i;
m.insert(-2147483647);
m.insert(2147483647);
for (i = 0;i < q;i++)
{
int op, x;
cin >> op >> x;
if (op == 5)
{
m.insert(x);
}
else if (op == 1)
{
auto it = m.lower_bound(x);
p = 0;
for (auto i = m.begin();i != it;i++)
{
p++;
}
cout << p << "\n";
}
else if (op == 2)
{
p = -1;
for (auto i:m)
{
if (++p == x)
{
cout << 1 << "\n";
}
}
}
else if (op == 3)
{
auto it = m.lower_bound(x);
cout << *it-- << "\n";
}
else if (op == 4)
{
cout << *m.upper_bound(x) << "\n";
}
}
return 0;
}