#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int MAXN = 1000100;
int q = 0, qq, n;
int mn[2];
int pos[MAXN];
struct quer {
  int a, t, x;
  int pos;
};
quer que[MAXN];
map<int, int> xz;
vector<vector<pair<long long, long long> > > ms;
vector<vector<int> > fen;
void add(vector<int>& fn, int pos, int val) {
  for (int i = pos; i < fn.size(); i |= i + 1) {
    fn[i] += val;
  }
}
int sum(vector<int>& fn, int pos) {
  int ans = 0;
  for (int i = pos; i >= 0; i = (i & (i + 1)) - 1) {
    ans += fn[i];
  }
  return ans;
}
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &que[i].a, &que[i].t, &que[i].x);
    xz[que[i].x];
  }
  int k = 0;
  for (auto it = xz.begin(); it != xz.end(); ++it) (*it).second = k++;
  ms.resize(k);
  fen.resize(k);
  for (int i = 0; i < n; ++i) {
    int x = xz[que[i].x];
    ms[x].push_back(pair<long long, long long>(que[i].t, i));
  }
  for (int i = 0; i < ms.size(); ++i) {
    sort(ms[i].begin(), ms[i].end());
    for (int j = 0; j < ms[i].size(); ++j) {
      que[ms[i][j].second].pos = j;
    }
    fen[i].resize(ms[i].size());
  }
  for (int i = 0; i < n; ++i) {
    int x = xz[que[i].x];
    if (que[i].a != 3) {
      add(fen[x], que[i].pos, (que[i].a == 1 ? 1 : -1));
    } else {
      printf("%d\n", sum(fen[x], que[i].pos));
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  solve();
  return 0;
}
