#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int segTree[N * 4], n, x, y, z, l, r, val;
map<int, int> TMp, NMp;
vector<pair<int, int>> vv;
vector<int> v, numm[N];
struct Query {
  int type, tim, num, ind;
};
Query q[N];
void update(int i, int j, int pos) {
  if (i > r || j < l) return;
  if (i == j) {
    if (val == 0)
      segTree[pos] = 0;
    else
      segTree[pos] += val;
    return;
  }
  int mid = (i + j) / 2;
  update(i, mid, pos * 2);
  update(mid + 1, j, pos * 2 + 1);
  segTree[pos] = segTree[pos * 2] + segTree[pos * 2 + 1];
}
int get(int i, int j, int pos) {
  if (i > r || j < l) {
    return 0;
  }
  if (l <= i && r >= j) {
    return segTree[pos];
  }
  int mid = (i + j) / 2;
  return get(i, mid, pos * 2) + get(mid + 1, j, pos * 2 + 1);
}
int main() {
  scanf("%d", &n);
  int c = 1;
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (NMp[z] == 0) {
      NMp[z] = c;
      c++;
    }
    numm[NMp[z]].push_back(i);
    q[i].type = x;
    q[i].tim = y;
    q[i].num = NMp[z];
    q[i].ind = i;
    v.push_back(y);
  }
  sort(v.begin(), v.end());
  int co = 1;
  for (int i = 0; i < v.size(); i++) {
    if (TMp[v[i]] == 0) {
      TMp[v[i]] = co;
      co++;
    }
  }
  for (int j = 1; j < c; j++) {
    for (int i = 0; i < numm[j].size(); i++) {
      int x = numm[j][i];
      if (q[x].type == 1) {
        l = TMp[q[x].tim];
        r = TMp[q[x].tim];
        val = 1;
        update(1, N, 1);
      } else if (q[x].type == 2) {
        l = TMp[q[x].tim];
        r = TMp[q[x].tim];
        val = -1;
        update(1, N, 1);
      } else if (q[x].type == 3) {
        l = 1;
        r = TMp[q[x].tim];
        int ans = get(1, N, 1);
        vv.push_back(make_pair(q[x].ind, ans));
      }
    }
    for (int i = 0; i < numm[j].size(); i++) {
      l = TMp[q[numm[j][i]].tim];
      r = TMp[q[numm[j][i]].tim];
      val = 0;
      update(1, N, 1);
    }
  }
  sort(vv.begin(), vv.end());
  for (int i = 0; i < vv.size(); i++) {
    printf("%d\n", vv[i].second);
  }
  return 0;
}
