# include <bits/stdc++.h>
using namespace std;

int main() {
    int num_query; scanf("%d", &num_query);
    int command, x, left, right;
    set<int> S;
    
    for (int i = 0; i < num_query; ++i) {
        scanf("%d", &command);
        int find_result = 0;
        switch (command) {
            case 0:
                scanf("%d", &x);
                S.insert(x);
                printf("%d\n", (int) S.size());
                break;
            case 1:
                scanf("%d", &x);
                if (S.find(x) != S.end()) find_result = 1;
                printf("%d\n", find_result);
                break;
            case 2:
                scanf("%d", &x);
                S.erase(x);
                break;
            case 3:
                scanf("%d%d", &left, &right);
                auto lower_itr = S.lower_bound(left);
                auto upper_itr = S.upper_bound(right);
                for (auto itr = lower_itr; itr != upper_itr; ++itr) printf("%d\n", *itr);
                break;
        }
    }
    return 0;
}
