#include <bits/stdc++.h>
using namespace std;
struct _3tuple {
  int a, t, x;
};
vector<_3tuple>& get_input() {
  int n;
  scanf("%i", &n);
  vector<_3tuple>& ans = *new vector<_3tuple>(n);
  for (auto& it : ans) scanf("%i %i %i", &it.a, &it.t, &it.x);
  return ans;
}
struct node {
  int mid_t;
  int sum;
  node() : mid_t(0), sum(0){};
};
class seg_tree {
  vector<node> m;
  const int SZ;
  void rec_build(int p, int l, int r, vector<int>& times) {
    assert(l < r);
    if (r - l == 1) {
      m[p].mid_t = times[l];
      return;
    }
    int mid = (l + r) >> 1;
    m[p].mid_t = times[mid];
    rec_build(p * 2 + 1, l, mid, times);
    rec_build(p * 2 + 2, mid, r, times);
  }
  void add_val(int p, int l, int r, int t, int val) {
    assert(l < r);
    if (r - l > 1) {
      int mid = (l + r) >> 1;
      if (t < m[p].mid_t)
        add_val(p * 2 + 1, l, mid, t, val);
      else
        add_val(p * 2 + 2, mid, r, t, val);
    }
    m[p].sum += val;
  }
  int get_sum(int p, int l, int r, int tr) {
    assert(l < r);
    if (r - l == 1) return m[p].mid_t < tr ? m[p].sum : 0;
    int mid = (l + r) >> 1;
    m[p].mid_t;
    if (tr < m[p].mid_t) return get_sum(p * 2 + 1, l, mid, tr);
    return m[p * 2 + 1].sum + get_sum(p * 2 + 2, mid, r, tr);
  }

 public:
  seg_tree(vector<int>& times) : m(times.size() * 4), SZ(times.size()) {
    rec_build(0, 0, SZ, times);
  };
  inline int count(int time) { return get_sum(0, 0, SZ, time); }
  inline void add(int time) { add_val(0, 0, SZ, time, +1); }
  inline void del(int time) { add_val(0, 0, SZ, time, -1); }
};
void solve() {
  vector<_3tuple>& quest = get_input();
  map<int, vector<int> > time_table;
  for (auto& it : quest) time_table[it.x].push_back(it.t);
  vector<int> vals;
  vector<seg_tree> trees;
  vals.reserve(time_table.size());
  trees.reserve(time_table.size());
  for (auto& it : time_table)
    sort(it.second.begin(), it.second.end()), vals.push_back(it.first),
        trees.emplace_back(it.second);
  for (auto& it : quest) {
    int i = lower_bound(vals.begin(), vals.end(), it.x) - vals.begin();
    if (i == (int)vals.size())
      printf("0\n");
    else
      switch (it.a) {
        case 1:
          trees[i].add(it.t);
          break;
        case 2:
          trees[i].del(it.t);
          break;
        case 3:
          printf("%i\n", trees[i].count(it.t));
          break;
      }
  }
}
int main() {
  solve();
  return 0;
}
