#include <bits/stdc++.h>
using namespace std;
int ans[100001];
vector<pair<int, int> > v;
inline void solve() {
  vector<int> add, sub;
  for (int it = 0; it < v.size(); it++) {
    int tp = v[it].first % 10;
    if (tp == 1) {
      add.push_back(v[it].second);
      if (add.size() % 444 == 0) sort(add.end() - 444, add.end());
    } else if (tp == 2) {
      sub.push_back(v[it].second);
      if (sub.size() % 444 == 0) sort(sub.end() - 444, sub.end());
    } else {
      int idx = v[it].first / 10;
      int res = 0;
      for (int i = 0; i < add.size(); i += 444) {
        int j = i + 444;
        if (j <= add.size()) {
          int foo =
              upper_bound(add.begin() + i, add.begin() + j, v[it].second) -
              (add.begin() + i);
          res += foo;
        } else {
          sort(add.begin() + i, add.end());
          int foo = upper_bound(add.begin() + i, add.end(), v[it].second) -
                    (add.begin() + i);
          res += foo;
          break;
        }
      }
      for (int i = 0; i < sub.size(); i += 444) {
        int j = i + 444;
        if (j <= sub.size()) {
          int foo =
              upper_bound(sub.begin() + i, sub.begin() + j, v[it].second) -
              (sub.begin() + i);
          res -= foo;
        } else {
          sort(sub.begin() + i, sub.end());
          int foo = upper_bound(sub.begin() + i, sub.end(), v[it].second) -
                    (sub.begin() + i);
          res -= foo;
          break;
        }
      }
      ans[idx] = res;
    }
  }
  v.clear();
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, tp, t, x;
  cin >> n;
  vector<pair<int, pair<int, int> > > input(n);
  for (int i = 0; i < n; i++) {
    cin >> tp >> t >> x;
    input[i].first = x;
    input[i].second = make_pair(tp + 10 * i, t);
  }
  sort(input.begin(), input.end());
  memset(ans, -1, sizeof ans);
  v.push_back(input[0].second);
  for (int i = 1; i < n; i++) {
    if (input[i].first != input[i - 1].first) solve();
    v.push_back(input[i].second);
  }
  solve();
  for (int i = 0; i < 100001; i++)
    if (ans[i] > -1) cout << ans[i] << '\n';
  return 0;
}
