#include <bits/stdc++.h>

using namespace std;

int main() 
{
    int n, x, y, z, i;
    scanf("%d", &n);
    
    set<int> s;
    
    for(i = 0; i < n; i++)
    {
        scanf("%d %d", &x, &y);
        
        if(x == 0)
        {
            s.insert(y);
            printf("%d\n", (int)s.size());
        }
        else if(x == 1)
        {
            printf("%d\n", (int)s.count(y));
        }
        else if(x == 2)
        {
            s.erase(y);
        }
        else if(x == 3)
        {
            scanf("%d", &z);
            
            auto L = s.lower_bound(y);
            auto R = s.upper_bound(z);
            
            while(L != R)
            {
                printf("%d\n", *L);
                L++;
            }
        }
    }
    
    return 0;
}
