#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

int main() {
    set<int> s;
    int q; cin >> q;
    while (q--) {
        int com, x; cin >> com >> x;
        if (com == 0) {
            s.emplace(x);
            cout << s.size() << endl;
        } else if (com == 1) {
            cout << s.count(x) << endl;
        } else if (com == 2) {
            s.erase(x);
        } else if (com == 3) {
            int y; cin >> y;
            auto it = s.lower_bound(x);
            while (it != s.end() && *it <= y) {
                cout << *it << endl;
                it++;
            }
        }
    }
    return 0;
}
