#include <bits/stdc++.h>
const int maxn = (int)1e6 + 5;
using namespace std;
unordered_map<int, int> t[maxn * 4];
unordered_map<int, int> empty;
void build(int n) {
  for (int i = 0; i <= (n * 4); i++) {
    t[i] = empty;
  }
}
int sum(int v, int trl, int trr, int l, int r, int val) {
  if (l > r) return 0;
  if (l == trl && r == trr) return t[v][val];
  int trm = (trl + trr) / 2;
  return sum(v * 2 + 1, trl, trm, l, min(r, trm), val) +
         sum(v * 2 + 2, trm + 1, trr, max(l, trm + 1), r, val);
}
void update(int v, int trl, int trr, int pos, int val) {
  if (trl == trr)
    t[v][val]++;
  else {
    int trm = (trl + trr) / 2;
    if (pos <= trm)
      update(v * 2 + 1, trl, trm, pos, val);
    else
      update(v * 2 + 2, trm + 1, trr, pos, val);
    t[v][val] = t[v * 2 + 1][val] + t[v * 2 + 2][val];
  }
}
void _delete(int v, int trl, int trr, int pos, int val) {
  if (trl == trr) {
    t[v][val]--;
  } else {
    int trm = (trl + trr) / 2;
    if (pos <= trm) {
      _delete(v * 2 + 1, trl, trm, pos, val);
    } else {
      _delete(v * 2 + 2, trm + 1, trr, pos, val);
    }
    t[v][val] = t[v * 2 + 1][val] + t[v * 2 + 2][val];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  build(n);
  vector<int> a;
  vector<pair<pair<int, int>, int> > qs;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back(y);
    qs.push_back(make_pair(make_pair(x, y), z));
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    int x = qs[i].first.first;
    int y = qs[i].first.second;
    int z = qs[i].second;
    switch (x) {
      case 1:
        update(1, 1, n, ((lower_bound(a.begin(), a.end(), y) - a.begin()) + 1),
               z);
        break;
      case 2:
        _delete(1, 1, n, ((lower_bound(a.begin(), a.end(), y) - a.begin()) + 1),
                z);
        break;
      case 3:
        cout << sum(1, 1, n, 1,
                    ((lower_bound(a.begin(), a.end(), y) - a.begin()) + 1), z)
             << endl;
        break;
    }
  }
  return 0;
}
