#include <bits/stdc++.h>
using namespace std;
int n;
map<int, vector<int>> fw;
map<int, set<int>> tmps;
map<int, int> ord;
int32_t main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> n;
  vector<pair<int, pair<int, int>>> qr;
  set<int> elem;
  for (int i = 1; i <= n; i++) {
    int a, t, x;
    cin >> a >> t >> x;
    qr.push_back(make_pair(a, make_pair(t, x)));
    elem.insert(x);
    tmps[x].insert(t);
  }
  while (!elem.empty()) {
    int x = *elem.begin();
    fw[x].assign((int)(tmps[x].size()) + 5, 0);
    int c = 1;
    while (!tmps[x].empty()) {
      int t = *tmps[x].begin();
      ord[t] = c;
      c++;
      tmps[x].erase(tmps[x].begin());
    }
    elem.erase(elem.begin());
  }
  for (int i = 0; i < qr.size(); i++) {
    auto q = qr[i];
    int a = q.first;
    int t = q.second.first;
    int x = q.second.second;
    if (a == 3) {
      int cnt = 0;
      for (int j = ord[t]; j > 0; j -= (j & (-j))) {
        cnt += fw[x][j];
      }
      cout << cnt << "\n";
    }
    if (a == 2) {
      for (int j = ord[t]; j < fw[x].size(); j += (j & (-j))) {
        fw[x][j]--;
      }
    }
    if (a == 1) {
      for (int j = ord[t]; j < fw[x].size(); j += (j & (-j))) {
        fw[x][j]++;
      }
    }
  }
  return 0;
}
