#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;
}
struct Input {
  int n;
  vector<pair<int, pair<int, int>>> q;
  bool read() {
    if (!(cin >> n)) {
      return false;
    }
    for (int i = 0; i < n; ++i) {
      int type;
      int t, x;
      scanf("%d%d%d", &type, &t, &x);
      q.push_back(make_pair(type, make_pair(t, x)));
    }
    return true;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  vector<int> ans;
  void write() {
    for (int i = 0; i < ((int)(ans).size()); ++i) {
      printf("%d\n", ans[i]);
    }
  }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
class FenTree {
 public:
  vector<int> a;
  FenTree(int n = 0) : a(n + 1, 0) {}
  void add(int x, int d) {
    while (x < ((int)(a).size())) {
      a[x] += d;
      x |= x + 1;
    }
  }
  int get(int x) {
    int res = 0;
    while (x >= 0) {
      res += a[x];
      x &= x + 1;
      --x;
    }
    return res;
  }
};
const int N = 1e6 + 42;
struct Solution : Data {
  vector<FenTree> st;
  vector<vector<int>> tt;
  int getNum(vector<int> const& a, int x) {
    return lower_bound((a).begin(), (a).end(), x) - a.begin();
  }
  void unique(vector<int>& a) {
    sort((a).begin(), (a).end());
    a.resize(std::unique((a).begin(), (a).end()) - a.begin());
  }
  void solve() {
    vector<int> xs;
    for (int i = 0; i < ((int)(q).size()); ++i) {
      int x = q[i].second.second;
      xs.push_back(x);
    }
    unique(xs);
    tt.resize(((int)(xs).size()));
    for (int i = 0; i < ((int)(q).size()); ++i) {
      int t = q[i].second.first;
      int x = q[i].second.second = getNum(xs, q[i].second.second);
      tt[x].push_back(t);
    }
    for (int i = 0; i < ((int)(tt).size()); ++i) {
      unique(tt[i]);
    }
    st.resize(((int)(xs).size()));
    for (int i = 0; i < ((int)(xs).size()); ++i) {
      st[i] = FenTree(((int)(tt[i]).size()));
    }
    for (int i = 0; i < ((int)(q).size()); ++i) {
      int type = q[i].first;
      int x = q[i].second.second;
      int t = getNum(tt[x], q[i].second.first);
      ;
      if (type == 1) {
        st[x].add(t, 1);
      } else if (type == 2) {
        st[x].add(t, -1);
      } else {
        ans.push_back(st[x].get(t));
      }
    }
  }
  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;
}
