#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.setf(ios::fixed);
  cout.precision(9);
  cerr.setf(ios::fixed);
  cerr.precision(3);
  int n = 1;
  for (int i = 0; i < n; i++) {
    solve(i + 1);
  }
  return 0;
}
const int MAXN = 100010;
int n;
int a[MAXN], t[MAXN], q[MAXN];
int res[MAXN];
int sorted[MAXN];
vector<int> aa[MAXN];
vector<int> tt[MAXN];
vector<int> id[MAXN];
inline void add(vector<int> &t, int v, int vl, int vr, int pos, int val) {
  if (vl + 1 == vr) {
    t[v] += val;
    return;
  }
  int d = (vl + vr) / 2;
  if (pos < d) {
    add(t, v * 2, vl, d, pos, val);
  } else {
    add(t, v * 2 + 1, d, vr, pos, val);
  }
  t[v] = t[v * 2] + t[v * 2 + 1];
}
inline int get(vector<int> &t, int v, int vl, int vr, int l, int r) {
  if (l >= r) return 0;
  if (vl == l && vr == r) {
    return t[v];
  }
  int d = (vl + vr) / 2;
  int r1 = get(t, v * 2, vl, d, l, min(d, r));
  int r2 = get(t, v * 2 + 1, d, vr, max(l, d), r);
  return r1 + r2;
}
inline void solve(vector<int> &a, vector<int> &t, vector<int> &id) {
  vector<int> tt(t);
  sort(tt.begin(), tt.end());
  for (auto &cur : t) {
    cur = lower_bound(tt.begin(), tt.end(), cur) - tt.begin();
  }
  vector<pair<int, pair<int, int> > > all(a.size());
  for (int i = 0; i < (int)a.size(); i++) {
    all[i] = {t[i], {a[i], id[i]}};
  }
  int n = a.size() + 5;
  vector<int> tree(n * 4 + 2, 0);
  for (auto cur : all) {
    int t = cur.first;
    int op = cur.second.first;
    int id = cur.second.second;
    if (op == 1) {
      add(tree, 1, 0, n, t, 1);
    } else if (op == 2) {
      add(tree, 1, 0, n, t, -1);
    } else {
      res[id] = get(tree, 1, 0, n, 0, t);
    }
  }
}
void solve(int test_number) {
  cin >> n;
  map<int, int> dic;
  int last = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> t[i] >> q[i];
    if (dic.count(q[i]) == 0) {
      dic[q[i]] = last;
      last++;
    }
    int cur = dic[q[i]];
    aa[cur].push_back(a[i]);
    tt[cur].push_back(t[i]);
    id[cur].push_back(i);
  }
  for (int i = 0; i < last; i++) {
    solve(aa[i], tt[i], id[i]);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 3) {
      cout << res[i] << "\n";
    }
  }
}
