#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
char buf[65537];
char *ch = buf;
inline char get_char() {
  if (*ch == 0) {
    ch = buf;
    fread(buf, sizeof(char), 65536, stdin);
  }
  return *(ch++);
}
char _ch;
inline void next_int(int &ans) {
  ans = 0;
  while ((_ch = get_char()) < '0' || _ch > '9')
    ;
  do {
    ans = ans * 10 + _ch - '0';
  } while ((_ch = get_char()) >= '0' && _ch <= '9');
}
char res[22];
inline void out(int ans) {
  int k = 0;
  while (ans > 0) {
    res[k++] = ans % 10 + '0';
    ans /= 10;
  }
  if (!k) {
    res[k++] = '0';
  }
  res[k] = 0;
  reverse(res, res + k);
  puts(res);
}
int a, b, c, d, n, m, k;
pair<int, pair<int, int> > quer[1000002];
int nums[1000002];
int cnt[1000002], beg[1000002], pnt[1000002], fen[1000002];
inline void upd(int *fen, int first, int len, int val) {
  for (; first < len; first |= first + 1) fen[first] += val;
}
inline int fnd(int *fen, int first) {
  int ans = 0;
  for (; first >= 0; first = (first & (first + 1)) - 1) ans += fen[first];
  return ans;
}
int main() {
  next_int(n);
  for (int _n((n)-1), i(0); i <= _n; i++) {
    next_int(a);
    next_int(b);
    next_int(c);
    quer[i] = make_pair(a, make_pair(b, c));
    nums[i] = c;
  }
  sort(nums, nums + n);
  k = unique(nums, nums + n) - nums;
  for (int _n((n)-1), i(0); i <= _n; i++) {
    int t = lower_bound(nums, nums + k, quer[i].second.second) - nums;
    quer[i].second.second = t;
    ++cnt[quer[i].second.second];
  }
  for (int _n((k)-1), i(0); i <= _n; i++) {
    if (i) {
      beg[i] = beg[i - 1] + cnt[i - 1];
    } else {
      beg[i] = 0;
    }
  }
  memset((cnt), 0, sizeof(cnt));
  for (int _n((n)-1), i(0); i <= _n; i++) {
    c = quer[i].second.second;
    pnt[beg[c] + cnt[c]++] = quer[i].second.first;
  }
  for (int _n((k)-1), i(0); i <= _n; i++) {
    sort(pnt + beg[i], pnt + beg[i] + cnt[i]);
    cnt[i] = unique(pnt + beg[i], pnt + beg[i] + cnt[i]) - (pnt + beg[i]);
  }
  for (int _n((n)-1), i(0); i <= _n; i++) {
    c = quer[i].second.second;
    int t =
        lower_bound(pnt + beg[c], pnt + beg[c] + cnt[c], quer[i].second.first) -
        (pnt + beg[c]);
    if (quer[i].first == 1) {
      upd(fen + beg[c], t, cnt[c], 1);
    } else if (quer[i].first == 2) {
      upd(fen + beg[c], t, cnt[c], -1);
    } else {
      int ans = fnd(fen + beg[c], t);
      out(ans);
    }
  }
}
