#include <bits/stdc++.h>
using namespace std;
void fw_update(vector<pair<int, int> > &f, int pos, int diff) {
  for (int i = pos; i < f.size(); i += i & (-i)) {
    f[i].second += diff;
  }
}
int fw_sum(vector<pair<int, int> > &f, int pos) {
  int res = 0;
  for (int i = pos; i >= 1; i -= i & (-i)) {
    res += f[i].second;
  }
  return res;
}
int main(int argc, char **argv) {
  int n;
  scanf("%d", &n);
  map<int, vector<pair<int, int> > > q;
  vector<int> a(n), t(n), x(n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d%d", &a[i], &t[i], &x[i]);
    q[x[i]].push_back(make_pair(t[i], 0));
  }
  for (map<int, vector<pair<int, int> > >::iterator it = q.begin();
       it != q.end(); ++it) {
    it->second.push_back(make_pair(0, 0));
    sort(it->second.begin(), it->second.end());
  }
  for (int i = 0; i < n; i++) {
    vector<pair<int, int> > &f = q[x[i]];
    vector<pair<int, int> >::iterator it;
    it = lower_bound(f.begin(), f.end(), make_pair(t[i], -n));
    int idx = it - f.begin();
    switch (a[i]) {
      case 1:
        fw_update(f, idx, +1);
        break;
      case 2:
        fw_update(f, idx, -1);
        break;
      default:
        printf("%d\n", fw_sum(f, idx));
        break;
    }
  }
  return 0;
}
