#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(12);
  cout << fixed;
  smain();
  return 0;
}
int n;
int ans[1000001];
int f[1000001];
inline int sum(int r) {
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += f[r];
  return result;
}
inline void inc(int i, int delta) {
  for (; i < n; i = (i | (i + 1))) f[i] += delta;
}
void solve(vector<pair<int, pair<int, int> > > &q) {
  vector<int> ts;
  ts.reserve(q.size());
  for (auto it : q) ts.push_back(it.first);
  sort(ts.begin(), ts.end());
  ts.resize(unique(ts.begin(), ts.end()) - ts.begin());
  int m = ts.size();
  memset(f, 0, sizeof(int) * m);
  for (auto it : q) {
    int tp = it.second.first;
    int t = lower_bound(ts.begin(), ts.end(), it.first) - ts.begin();
    if (tp == 1) {
      inc(t, 1);
    } else if (tp == 2) {
      inc(t, -1);
    } else {
      ans[it.second.second] = sum(t);
    }
  }
}
void smain() {
  for (; scanf("%d", &n) != EOF;) {
    map<int, vector<pair<int, pair<int, int> > > > q;
    for (int i = 0; i < n; i++) {
      int a, t, x;
      scanf("%d %d %d", &a, &t, &x);
      q[x].emplace_back(t, make_pair(a, i));
    }
    memset(ans, 255, sizeof(int) * n);
    for (auto it : q) solve(it.second);
    for (int i = 0; i < n; i++)
      if (ans[i] != -1) printf("%d\n", ans[i]);
  }
}
