#include <bits/stdc++.h>
using namespace std;
class query {
 public:
  int t, v, m;
  query() {}
  query(int a, int b, int c) {
    t = a;
    v = b;
    m = c;
  }
};
map<int, int> V;
map<int, int> T[1000010];
vector<int> BITS[1000010];
query Q[1000010];
int val[1000010];
vector<int> mom[1000010];
int idv;
int idt[10000010];
void upd(vector<int>& B, int p, int v) {
  int N = (int)B.size();
  while (p < N) {
    B[p] += v;
    p += p & -p;
  }
}
int query(vector<int>& B, int p) {
  int sum = 0;
  while (p > 0) {
    sum += B[p];
    p -= p & -p;
  }
  return sum;
}
int main() {
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d %d", &Q[i].t, &Q[i].m, &Q[i].v);
  }
  for (int i = 0; i < q; i++) val[i] = Q[i].v;
  sort(val, val + q);
  idv = 0;
  for (int i = 0; i < q; i++) {
    if (i == 0 || val[i] != val[i - 1]) V[val[i]] = idv++;
  }
  for (int i = 0; i < q; i++) {
    Q[i].v = V[Q[i].v];
    mom[Q[i].v].push_back(Q[i].m);
  }
  for (int i = 0; i < idv; i++) {
    sort(mom[i].begin(), mom[i].end());
    idt[i] = 1;
    for (int j = 0; j < (int)mom[i].size(); j++) {
      if (j == 0 || mom[i][j] != mom[i][j - 1]) T[i][mom[i][j]] = idt[i]++;
    }
    BITS[i] = vector<int>(idt[i] + 10, 0);
  }
  for (int i = 0; i < q; i++) Q[i].m = T[Q[i].v][Q[i].m];
  for (int i = 0; i < q; i++) {
    int T = Q[i].t;
    if (T == 1) {
      upd(BITS[Q[i].v], Q[i].m, 1);
    } else if (T == 2) {
      upd(BITS[Q[i].v], Q[i].m, -1);
    } else
      printf("%d\n", query(BITS[Q[i].v], Q[i].m));
  }
  return 0;
}
