#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
int n;
unordered_map<ll, int> dic;
tree<pair<ll, int>, null_type,
less<pair<ll, int>>, rb_tree_tag,
tree_order_statistics_node_update>
tr;
int main()
{
int opt{};
ll x;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%d %lld", &opt, &x);
if (opt == 1)
{
tr.insert(make_pair(x, i));
dic[x]++;
}
if (opt == 2)
{
tr.erase(make_pair(x, dic[x]));
dic[x]--;
}
if (opt == 3)
{
auto it = tr.order_of_key(make_pair(x, 0));
printf("%ld\n", ++it);
}
if (opt == 4)
{
auto it = tr.find_by_order(x - 1);
printf("%lld\n", it->first);
}
if (opt == 5)
{
auto it = tr.lower_bound(make_pair(x, 0));
printf("%lld\n", (--it)->first);
}
if (opt == 6)
{
auto it = tr.upper_bound(make_pair(x, dic[x]));
printf("%lld\n", it->first);
}
}
return 0;
}
RT,可过样例,求调