#include<bits/stdc++.h>
#include <map>
#include <set>
using namespace std;
multiset<int> m;
void insertValue(int x) {
//TODO 实现插入逻辑
m.insert(x);
}
void eraseValue(int x) {
//TODO 实现删除逻辑
auto it = m.find(x);
if (it != m.end()) {
m.erase(it);
}
}
int xCount(int x) {
//TODO 求x在集合中的个数
return m.count(x);
}
int sizeOfSet() {
//TODO 返回集合大小
return m.size();
}
int getPre(int x) {
//TODO 实现找前驱
auto it = m.lower_bound(x);
if (it == m.begin()) {
return -1;
}
return *(--it);
}
int getBack(int x) {
//TODO 实现找后继
auto it = m.upper_bound(x);
if (it == m.end()) {
return -1;
} else {
return *it;
}
}
int main() {
int q, op, x;
cin >> q;
while (q--) {
cin >> op;
if (op == 1) {
cin >> x;
insertValue(x);
}
if (op == 2) {
cin >> x;
eraseValue(x);
}
if (op == 3) {
cin >> x;
cout << xCount(x) << endl;
}
if (op == 4) {
cout << sizeOfSet() << endl;
}
if (op == 5) {
cin >> x;
cout << getPre(x) << endl;
}
if (op == 6) {
cin >> x;
cout << getBack(x) << endl;
}
}
return 0;
}