#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int a[N];
int t[N];
int x[N];
vector<int> it[N];
vector<int> ff[N];
int get(int x, const vector<int> &a) {
  auto it = lower_bound(a.begin(), a.end(), x);
  assert(*it == x);
  return it - a.begin();
}
void upd(int xx, int pos, int val) {
  for (int i = pos; i < (int)ff[xx].size(); i |= i + 1) {
    ff[xx][i] += val;
  }
}
int sum(int xx, int pos) {
  int res = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
    res += ff[xx][i];
  }
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  vector<int> xx, tt;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &t[i], &x[i]);
    xx.push_back(x[i]);
    tt.push_back(t[i]);
  }
  sort(xx.begin(), xx.end());
  xx.erase(unique(xx.begin(), xx.end()), xx.end());
  sort(tt.begin(), tt.end());
  xx.erase(unique(tt.begin(), tt.end()), tt.end());
  for (int i = 0; i < n; i++) {
    int nx = get(x[i], xx);
    int nt = get(t[i], tt);
    it[nx].push_back(nt);
    ff[nx].push_back(0);
    x[i] = nx;
    t[i] = nt;
  }
  for (int i = 0; i < (int)xx.size(); i++) {
    sort(it[i].begin(), it[i].end());
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      int at = get(t[i], it[x[i]]);
      upd(x[i], at, 1);
    } else if (a[i] == 2) {
      int at = get(t[i], it[x[i]]);
      upd(x[i], at, -1);
    } else {
      int at = get(t[i], it[x[i]]);
      printf("%d\n", sum(x[i], at));
    }
  }
  return 0;
}
