#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int sN = 350;
int n, m;
int qa[N], qt[N], qx[N];
map<int, int> mp, st[N], stb[sN];
void update(int i, int x) {
  ++st[i][x];
  ++stb[i / sN][x];
}
void remove(int i, int x) {
  if (--st[i][x] == 0) st[i].erase(x);
  if (--stb[i / sN][x] == 0) stb[i / sN].erase(x);
}
int query(int i, int x) {
  int ans = 0;
  while (i >= 0 && i % sN != sN - 1) {
    ans += st[i].count(x) ? st[i][x] : 0;
    --i;
  }
  while (i >= 0) {
    ans += stb[i / sN].count(x) ? stb[i / sN][x] : 0;
    i -= sN;
  }
  return ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d%d", qa + i, qt + i, qx + i);
    if (qa[i] != 3) mp[qt[i]];
  }
  m = 0;
  for (auto &it : mp) it.second = m++;
  for (int i = 0; i < n; ++i) {
    if (qa[i] == 1)
      update(mp[qt[i]], qx[i]);
    else if (qa[i] == 2)
      remove(mp[qt[i]], qx[i]);
    else {
      auto flr = mp.upper_bound(qt[i]);
      if (flr != mp.begin()) --flr;
      if (flr == mp.end())
        printf("0\n");
      else
        printf("%d\n", query(flr->second, qx[i]));
    }
  }
}
