#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 8, lim = 4 * maxn;
int segtree[lim];
int len[maxn];
vector<int> tlist[maxn];
int ptr;
map<int, int> m;
int mapper(int num) {
  int val = m[num];
  if (val != 0) return val;
  m[num] = ++ptr;
  return ptr;
}
int query(int cur, int l, int r, int ql, int qr) {
  if (l > qr || r < ql) return 0;
  if (l >= ql && r <= qr) return segtree[cur];
  int lc = 2 * cur, rc = lc + 1, mid = (l + r) / 2;
  return (query(lc, l, mid, ql, qr) + query(rc, mid + 1, r, ql, qr));
}
void update(int cur, int l, int r, int pos, int val) {
  if (l > pos || r < pos) return;
  if (l == pos && r == pos) {
    segtree[cur] += val;
    return;
  }
  int lc = 2 * cur, rc = lc + 1, mid = (l + r) / 2;
  update(lc, l, mid, pos, val);
  update(rc, mid + 1, r, pos, val);
  segtree[cur] = segtree[lc] + segtree[rc];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  pair<int, pair<int, int> > q[n];
  vector<int> val;
  for (int i = 0; i < n; i++) {
    cin >> q[i].first >> q[i].second.first >> q[i].second.second;
    val.push_back(q[i].second.second);
  }
  sort(val.begin(), val.end());
  for (auto u : val) mapper(u);
  for (int i = 0; i < n; i++) {
    q[i].second.second = mapper(q[i].second.second);
    tlist[q[i].second.second].push_back(q[i].second.first);
  }
  for (int i = 0; i < maxn; i++) {
    if (tlist[i].size() == 0) continue;
    sort(tlist[i].begin(), tlist[i].end());
    std::vector<int>::iterator it;
    it = std::unique(tlist[i].begin(), tlist[i].end());
    tlist[i].resize(std::distance(tlist[i].begin(), it));
  }
  for (int i = 1; i < maxn; i++) len[i] = len[i - 1] + tlist[i].size();
  for (int i = 0; i < n; i++) {
    int l = len[q[i].second.second - 1] + 1;
    int r =
        l + (lower_bound(tlist[q[i].second.second].begin(),
                         tlist[q[i].second.second].end(), q[i].second.first) -
             tlist[q[i].second.second].begin());
    if (q[i].first == 1)
      update(1, 1, len[maxn - 1], r, 1);
    else if (q[i].first == 2)
      update(1, 1, len[maxn - 1], r, -1);
    else
      cout << query(1, 1, len[maxn - 1], l, r) << '\n';
  }
  return 0;
}
