#include <iostream>
#include<set>
#include<algorithm>
using namespace std;

int main()
{
    iostream::sync_with_stdio(0);
    set<int>s;
    int T,num=0;
    cin>>T;
    while(T--)
    {
        int flag,x;
        cin>>flag>>x;
        if(flag==0)
        {
            auto it=s.insert(x);
            if(it.second==1)
                num++;
            cout<<num<<endl;
        }
        else if(flag==1)
        {
            auto it=s.find(x);
            if(it==s.end())
            {
                cout<<0<<endl;
            }
            else cout<<1<<endl;
        }
        else if(flag==2)
        {
            int n=s.erase(x);
            num-=n;
        }
        else
        {
            int R;
            cin>>R;
            for(auto it=s.lower_bound(x);it!=s.end()&&*it<=R;it++)
            {

                    cout<<*it<<endl;

            }
        }
    }
  //  cout << "Hello world!" << endl;
    return 0;
}

