#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 10;
vector<pair<int, pair<int, int> > > V;
vector<int> F[MAX_N];
map<int, int> Map;
vector<int> List[MAX_N];
inline int Z(int a) { return a & ~(a - 1); }
inline void Add(int n, int k, int v) {
  const int l = F[n].size();
  for (; k < l; k += Z(k)) F[n][k] += v;
}
inline int Get(int n, int k) {
  int S = 0;
  for (; k > 0; k -= Z(k)) S += F[n][k];
  return S;
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < (N); ++i) {
    int type, pos, x;
    scanf("%d%d%d", &type, &pos, &x);
    if (!Map.count(x)) {
      int xx = Map.size();
      Map[x] = xx;
    }
    x = Map[x];
    V.push_back(make_pair(x, make_pair(type, pos)));
    List[x].push_back(V[i].second.second);
  }
  for (__typeof((Map).begin()) i = (Map).begin(); i != (Map).end(); ++i) {
    auto &l = List[i->second];
    sort((l).begin(), (l).end());
    F[i->second].resize(l.size() + 3);
  }
  for (__typeof((V).begin()) e = (V).begin(); e != (V).end(); ++e) {
    int x = e->first, type = e->second.first,
        pos =
            lower_bound((List[x]).begin(), (List[x]).end(), e->second.second) -
            List[x].begin() + 1;
    if (type == 1)
      Add(x, pos, +1);
    else if (type == 2)
      Add(x, pos, -1);
    else
      printf("%d\n", Get(x, pos));
  }
  return 0;
}
