#include <bits/stdc++.h>
using namespace std;
namespace Acc {
const int N = 1e6 + 10;
struct Q {
  int op, t, x, ans, id;
} q[N];
int n, a[N], cnt, buc[N], t[N];
set<int> S;
void add(int x, int k) {
  for (; x <= n; x += x & -x) t[x] += k;
}
int ask(int x) {
  int res = 0;
  for (; x >= 1; x -= x & -x) res += t[x];
  return res;
}
void work() {
  cin >> n;
  for (int i = 1, x, y, z; i <= n; i++)
    cin >> x >> y >> z, q[i] = {x, y, z, 0, i}, a[++cnt] = q[i].t;
  sort(a + 1, a + cnt + 1), cnt = unique(a + 1, a + cnt + 1) - a - 1;
  for (int i = 1; i <= n; i++)
    q[i].t = lower_bound(a + 1, a + cnt + 1, q[i].t) - a;
  sort(q + 1, q + cnt + 1,
       [](Q a, Q b) -> bool { return a.x < b.x || a.x == b.x && a.id < b.id; });
  for (int i = 1, now = q[1].x; i <= n; i++) {
    if (q[i].x != now) {
      for (auto j : S) add(j, -buc[j]), buc[j] = 0;
      S.clear(), now = q[i].x;
    }
    if (q[i].op == 1)
      add(q[i].t, 1), buc[q[i].t]++, S.insert(q[i].t);
    else if (q[i].op == 2)
      add(q[i].t, -1), buc[q[i].t]--, S.insert(q[i].t);
    else
      q[i].ans = ask(q[i].t);
  }
  sort(q + 1, q + cnt + 1, [](Q a, Q b) -> bool { return a.id < b.id; });
  for (int i = 1; i <= n; i++)
    if (q[i].op == 3) cout << q[i].ans << '\n';
}
}  // namespace Acc
int main() { return Acc::work(), 0; }
