#include <bits/stdc++.h>
using namespace std;
set<int> zeap;
int main() {
string line;
while (getline(cin, line)) {
stringstream ss(line);
string op;
ss >> op;
if (op == "I") {
int x;
ss >> x;
zeap.insert(x);
} else if (op == "S") {
int x;
ss >> x;
if (zeap.find(x) != zeap.end()) {
zeap.erase(x);
} else {
cout << "-1\n";
}
} else if (op == "C") {
int x;
ss >> x;
if (zeap.find(x) != zeap.end()) {
cout << "1\n";
} else {
cout << "0\n";
}
} else if (op == "MAX") {
if (zeap.size() < 2) {
cout << "-1\n";
} else {
int max_dif = *(zeap.rbegin()) - *(zeap.begin());
cout << max_dif << '\n';
}
} else if (op == "MIN") {
if (zeap.size() < 2) {
cout << "-1\n";
} else {
int min_dif = INT_MAX;
auto it = zeap.begin();
int prev = *it;
++it;
while (it != zeap.end()) {
min_dif = min(min_dif, *it - prev);
prev = *it;
++it;
}
cout << min_dif << '\n';
}
}
}
return 0;
}