#include <iostream>
#include <set>

int main(void) {
    int q{};
    std::cin >> q;

    std::set<int> my_set{};
    for (int i = 0; i < q; ++i) {
        int kind{};
        std::cin >> kind;

        int x{};
        switch (kind) {
            case 0:
                /// insert
                std::cin >> x;
                my_set.insert(x);
                std::cout << my_set.size() << std::endl;
                break;
            case 1:
                /// find
                std::cin >> x;
                if (my_set.find(x) != my_set.end())
                    std::cout << 1 << std::endl;
                else
                    std::cout << 0 << std::endl;

                break;
            case 2:
                /// delete
                std::cin >> x;
                my_set.erase(x);
                break;
            case 3:
                /// dump
                int l{}, r{};
                std::cin >> l >> r;
                auto iter_begin = my_set.lower_bound(l);
                auto iter_end = my_set.upper_bound(r);
                for (auto iter = iter_begin; iter != iter_end; ++iter)
                    std::cout << *iter << std::endl;

                break;
        }
    }
}
