#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

unsigned long xor128() {
  static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}

template <class T>
class Treap {
    std::size_t size_ = 0;
    struct Node {
        T key;
        int priority;
        Node *l, *r;
        Node(T key, int priority) : key(key), priority(priority), l(nullptr), r(nullptr) {}
    } *root = nullptr;
    using Tree = Node *;

    void split(Tree t, T key, Tree& l, Tree& r, bool by_upper_bound) {
        if (!t) {
            l = r = nullptr;
        } else if (key < t->key || (key == t->key && !by_upper_bound)) {
            split(t->l, key, l, t->l, by_upper_bound), r = t;
        } else {
            split(t->r, key, t->r, r, by_upper_bound), l = t;
        }
    }

    void split_by_lower_bound(Tree t, T key, Tree& l, Tree& r) {
      split(t,key,l,r,false);
    }
    void split_by_upper_bound(Tree t, T key, Tree& l, Tree& r) {
      split(t,key,l,r,true);
    }
    void split_into_tree_parts(Tree t, T key, Tree& l, Tree& c, Tree& r) {
      Tree tmp;
      split_by_lower_bound(t, key, l, tmp);
      split_by_upper_bound(tmp, key, c, r);
    }

    void merge(Tree& t, Tree l, Tree r) {
      if (!l || !r) {
        t = l ? l : r;
      } else if (l->priority > r->priority) {
        merge(l->r, l->r, r), t = l;
      } else {
        merge(r->l, l, r->l), t = r;
      }
    }
    void merge_three_trees(Tree& t, Tree l, Tree c, Tree r) {
      Tree tmp;
      merge(tmp, c, r);
      merge(t, l, tmp);
    }

    void insert(Tree& t, Tree item) {
      if (!t) {
        t = item;
      } else if (item->priority > t->priority) {
        split_by_lower_bound(t, item->key, item->l, item->r), t = item;
      } else {
        insert(item->key < t->key ? t->l : t->r, item);
      }
    }

    void erase(Tree& t, T key) {
      Tree l,r,c;
      split_into_tree_parts(t, key, l, c, r);
      merge(t, l, r);
      size_ -= nuke(c);
    }

    std::size_t find(Tree& t, T key) {
      Tree l,r,c;
      split_into_tree_parts(t, key, l, c, r);
      std::size_t ans = count(c);
      merge_three_trees(t, l, c, r);
      return ans;
    }

    std::size_t nuke(Tree t) {
      if (!t) return 0;
      std::size_t ret = 1;
      ret += nuke(t->l);
      ret += nuke(t->r);
      delete t;
      return ret;
    }

    std::size_t count(Tree t) {
      if (!t) return 0;
      std::size_t ret = 1;
      ret += count(t->l);
      ret += count(t->r);
      return ret;
    }

    void collect_(std::vector< T >& v, Tree t) {
      if (!t) return;
      collect_(v, t->l);
      v.emplace_back(t->key);
      collect_(v, t->r);
    }

  public:
    std::size_t size() const { return size_; }

    void insert(T key) {
      size_++;
      insert(root, new Node(key, xor128()));
    }

    void erase(T key) {
      erase(root, key);
    }

    std::size_t find(T key) {
      return find(root, key);
    }

    std::vector<T> collect(T x, T y) {
      std::vector<T> v;
      Tree l,r,c,tmp;
      split_by_lower_bound(root, x, l, tmp);
      split_by_upper_bound(tmp, y, c, r);
      collect_(v, c);
      merge(tmp, c, r);
      merge(root, l, tmp);
      return v;
    }
};

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  Treap< int > treap;
  int q; std::cin >> q;
  loop(q) {
    int c; std::cin >> c;
    if (c == 0) {
      int x; std::cin >> x;
      treap.insert(x);
      std::cout << treap.size() << std::endl;
    } else if (c == 1) {
      int x; std::cin >> x;
      std::size_t found = treap.find(x);
      std::cout << found << std::endl;
    } else if (c == 2) {
      int x; std::cin >> x;
      treap.erase(x);
    } else if (c == 3) {
      int l, r; std::cin >> l >> r;
      auto v = treap.collect(l,r);
      for (int x : v) {
        std::cout << x << std::endl;
      }
    }
    // debug(treap.collect(-10, 100));
  }
  return 0;
}


Measured memory_bytes: 10448