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

int main()
{
    set<int > s;
    int q;
    cin>>q;
    int b,tp1;
    while(q--){
        cin>>tp1;
        if(tp1==1){
                cin>>b;
            if(s.find(b)!=s.end()){
                cout<<"1\n";
            }
            else{
                cout<<"0\n";
            }
        }
        else if(tp1==0){
            cin>>b;
            s.insert(b);
            cout<<s.size()<<"\n";
        }
        else if(tp1==2){
            cin>>b;
            s.erase(b);
        }
        else{
            int r,l;
            cin>>l>>r;
            set<int>::iterator it=s.lower_bound(l);
            while(*it<=r&&it!=s.end()){
                cout<<*it<<"\n";
                it++;
            }
        }
    }

}


