#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    set<int> ss;
    int q;
    cin >> q;
    while (q--) {
        int t, x;
        cin >> t >> x;
        if (t == 1) {
            cout << ss.count(x) << endl;
        } else if (t == 0) {
            ss.insert(x);
            cout << ss.size() << endl;
        } else if (t == 2) {
            ss.erase(x);
        } else {
            int r;
            cin >> r;
            auto it = ss.lower_bound(x);
            for (; it != ss.end(); it++) {
                if (x <= *it && *it <= r) {
                    cout << *it << endl;
                }
                if (*it > r) break;
            }
        }
    } 
}
