#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vecll = vector<long long>;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main()
{
    ll q, que, x, y;
    set<ll> S;
    cin >> q;

    rep(i, q)
    {
        cin >> que >> x;
        if (que == 0)
            S.insert(x);
        else if (que == 2)
        {
            S.erase(x);
            continue;
        }
        else if (que == 3)
        {
            cin >> y;
            //delctype(S)
            set<ll>::iterator first_itr = S.lower_bound(x);
            set<ll>::iterator end_itr = S.upper_bound(y);

            for (auto i = first_itr; i != end_itr; ++i)
                cout << *i << endl;

            /*for (int i = x; i <= y; i++)
            {
                if (S.find(i) != S.end())
                {
                    cout << *S.find(i) << endl;
                }
            }*/

                /*for(struct { ll i; int j;} s = { x, 0} ; s.i <= y ; ++s.i , ++s.j)
            {
                if (S.find(s.i) != S.end())
                {
                    //cout << (s.j ? " " : "");
                    cout << *S.find(s.i) << endl;
                }
            }*/
                continue;
        }

        cout << (que ? S.count(x) : S.size()) << endl;
    }
    return 0;
}
