RT
#include <bits/stdc++.h>
using namespace std;
vector <int> a;
inline int read ()
{
int s = 0 , f = 1;
char c = getchar ();
while (c < '0' || c > '9')
{
if (c == '-') f = -1;
c = getchar ();
}
while (c >= '0' && c <= '9')
{
s = s * 10 + c - '0';
c = getchar ();
}
return f * s;
}
signed main()
{
int n = read () , cnt = 0;
for (int i = 1; i <= n; i++)
{
int opt = read () , x = read ();
if (opt == 1)
{
a.insert (upper_bound (a.begin() , a.end() , x) , x);
cnt++;
}
else if (opt == 2)
{
a.erase (lower_bound (a.begin() , a.end() , x));
cnt--;
}
else if (opt == 3)
{
long long ccnt = 1;
for (int i = 0; i <= int(a.size ()); i++)
{
if (x > a[i]) ccnt++;
}
cout << ccnt << "\n";
}
else if (opt == 4)
{
cout << a[x - 1] << "\n";
}
else if (opt == 5)
{
cout << a[(lower_bound (a.begin() , a.end() , x) - a) - 1];
}
else
{
cout << a[upper_bound (a.begin() , a.end() , x) - a];
}
}
return 0;
}