#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int N = 1000100;
struct Input {
  int n;
  int tp[N], t[N], x[N];
  bool read() {
    if (scanf("%d", &n) != 1) return 0;
    for (int i = int(0); i < int(n); ++i) {
      scanf("%d%d%d", &tp[i], &t[i], &x[i]);
    }
    return 1;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  vector<int> ans;
  void write() {
    for (int i = int(0); i < int(((int)(ans).size())); ++i) {
      printf("%d\n", ans[i]);
    }
  }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
struct seg_tree {
  int sz;
  vector<int> t;
  seg_tree() {}
  seg_tree(int n) {
    sz = 1;
    while (sz < n) sz <<= 1;
    t.assign(2 * sz, 0);
  }
  int fnd(int i, int x, int y, int l, int r) {
    if (x > r || y < l) return 0;
    if (x >= l && y <= r) {
      return t[i];
    }
    return fnd(2 * i, x, (x + y) >> 1, l, r) +
           fnd(2 * i + 1, ((x + y) >> 1) + 1, y, l, r);
  }
  void upd(int v, int k) {
    v += sz;
    while (v > 0) {
      t[v] += k;
      v >>= 1;
    }
  }
};
struct Solution : Data {
  seg_tree st[N];
  map<int, int> m;
  int ord[N];
  int cnt;
  vector<pair<int, int> > r[N];
  void solve() {
    for (int i = int(0); i < int(n); ++i) {
      ord[i] = x[i];
    }
    sort(ord, ord + n);
    cnt = 0;
    for (int i = 0; i < n;) {
      int j = i;
      for (; j < n && ord[i] == ord[j]; ++j)
        ;
      m[ord[i]] = cnt++;
      i = j;
    }
    for (int i = int(0); i < int(n); ++i) {
      x[i] = m[x[i]];
      r[x[i]].push_back(make_pair(t[i], i));
    }
    for (int i = int(0); i < int(cnt); ++i) {
      sort((r[i]).begin(), (r[i]).end());
      int tek = 0;
      for (int j = 0; j < ((int)(r[i]).size());) {
        int k = j;
        for (; k < ((int)(r[i]).size()) && r[i][k].first == r[i][j].first;
             ++k) {
          t[r[i][k].second] = tek;
        }
        tek++;
        j = k;
      }
      st[i] = seg_tree(tek);
    }
    for (int i = int(0); i < int(n); ++i) {
      if (tp[i] == 1) {
        st[x[i]].upd(t[i], 1);
      } else if (tp[i] == 2) {
        st[x[i]].upd(t[i], -1);
      } else {
        ans.push_back(st[x[i]].fnd(1, 0, st[x[i]].sz - 1, 0, t[i]));
      }
    }
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  sol.read();
  sol.solve();
  sol.write();
  return 0;
}
