#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  set<int> S;
  int q;
  cin >> q;
  while (q--) {
    int op, x;
    cin >> op >> x;
    if (op == 0) {
      S.insert(x);
      cout << S.size() << endl;
    } else if (op == 1) {
      cout << (S.find(x) != S.end()) << endl;
    } else if (op == 2) {
      S.erase(x);
    } else {
      int l = x, r;
      cin >> r;
      auto left = S.lower_bound(l);
      auto right = S.upper_bound(r);
      for (auto it = left; it != right; it++) {
        cout << *it << endl;
      }
    }
  }
}
