#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000000;
const long long int MOD = 1000000009;
const long long int P = 31;
int N;
long long int t[4 * MAXN] = {0};
long long int tp[4 * MAXN] = {0};
void make_push(int v, int l, int r, long long int tmp) {
  t[v] += (r - l + 1) * tmp;
  tp[v] += tmp;
}
void push(int v, int l, int r) {
  if (l != r) {
    make_push(2 * v + 1, l, (l + r) / 2, tp[v]);
    make_push(2 * v + 2, (l + r) / 2 + 1, r, tp[v]);
  }
  tp[v] = 0;
}
void update(int ql, int qr, long long int qv, int v = 0, int l = 0,
            int r = N - 1) {
  if (qr < l || r < ql) return;
  push(v, l, r);
  if (ql <= l && r <= qr) {
    make_push(v, l, r, qv);
  } else {
    update(ql, qr, qv, 2 * v + 1, l, (l + r) / 2);
    update(ql, qr, qv, 2 * v + 2, (l + r) / 2 + 1, r);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
  }
}
long long int get_ans(int qp, int v = 0, int l = 0, int r = N - 1) {
  if (qp < l || r < qp) return 0;
  push(v, l, r);
  if (qp <= l && r <= qp)
    return t[v];
  else
    return get_ans(qp, 2 * v + 1, l, (l + r) / 2) +
           get_ans(qp, 2 * v + 2, (l + r) / 2 + 1, r);
}
int A[MAXN], T[MAXN], X[MAXN];
int id[MAXN];
long long int ans[MAXN];
vector<int> ts;
bool cmp(int idl, int idr) {
  if (X[idl] != X[idr]) return X[idl] < X[idr];
  return idl < idr;
}
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d", &A[i], &T[i], &X[i]);
    id[i] = i;
  }
  sort(id, id + N, cmp);
  ts.reserve(N);
  int lb, rb = 0;
  int offs = 0, sz;
  int tid;
  while (rb < N) {
    lb = rb;
    while (rb < N && X[id[rb]] == X[id[lb]]) rb++;
    sz = rb - lb;
    for (int i = lb; i < rb; i++) {
      ts.push_back(T[id[i]]);
    }
    sort(ts.begin(), ts.end());
    for (int i = lb; i <= rb; i++) {
      tid = lower_bound(ts.begin(), ts.end(), T[id[i]]) - ts.begin();
      if (A[id[i]] == 1) {
        update(offs + tid, offs + sz - 1, 1);
      } else if (A[id[i]] == 2) {
        update(offs + tid, offs + sz - 1, -1);
      } else {
        ans[id[i]] = get_ans(offs + tid);
      }
    }
    offs += sz;
    ts.clear();
  }
  for (int i = 0; i < N; i++) {
    if (A[i] == 3) printf("%I64d\n", ans[i]);
  }
  return 0;
}
