#include <bits/stdc++.h>
std::set<int> add[100001], del[100001];
int a[100001], t[100001], x[100001], add_group[100001][101],
    del_group[100001][101];
int main(void) {
  int n;
  scanf("%d", &n);
  std::vector<int> X, Y;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", a + i, t + i, x + i);
    X.push_back(x[i]);
    Y.push_back(t[i]);
  }
  std::sort(X.begin(), X.end());
  X.erase(std::unique(X.begin(), X.end()), X.end());
  std::sort(Y.begin(), Y.end());
  Y.erase(std::unique(Y.begin(), Y.end()), Y.end());
  for (int i = 1; i <= n; i++) {
    x[i] = std::lower_bound(X.begin(), X.end(), x[i]) - X.begin() + 1;
    t[i] = std::lower_bound(Y.begin(), Y.end(), t[i]) - Y.begin() + 1;
  }
  X.clear();
  Y.clear();
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) {
      add_group[x[i]][t[i] / 1000]++;
      add[x[i]].insert(t[i]);
    } else if (a[i] == 2) {
      del_group[x[i]][t[i] / 1000]++;
      del[x[i]].insert(t[i]);
    } else {
      int result = 0;
      for (int j = 0; j < t[i] / 1000; j++)
        result += add_group[x[i]][j] - del_group[x[i]][j];
      auto it1 = add[x[i]].lower_bound(t[i] / 1000 * 1000),
           it2 = add[x[i]].upper_bound(t[i] / 1000 * 1000 + 999);
      for (; it1 != it2; it1++) {
        if (*it1 > t[i]) break;
        result++;
      }
      auto it3 = del[x[i]].lower_bound(t[i] / 1000 * 1000),
           it4 = del[x[i]].upper_bound(t[i] / 1000 * 1000 + 999);
      for (; it3 != it4; it3++) {
        if (*it3 > t[i]) break;
        result--;
      }
      printf("%d\n", result);
    }
  }
  return 0;
}
