#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int ans[MAXN], bit[MAXN], chck[MAXN];
int N;
int tt = 0;
int cur = 0;
vector<pair<int, pair<int, int> > > qr;
vector<pair<int, pair<int, int> > > v[MAXN];
void make();
void update(int pos, int val) {
  while (pos < MAXN) {
    if (chck[pos] != cur) {
      chck[pos] = cur;
      bit[pos] = 0;
    }
    bit[pos] += val;
    pos += (pos & -pos);
  }
}
int get(int pos) {
  int ans = 0;
  while (pos) {
    if (chck[pos] != cur) {
      chck[pos] = cur;
      bit[pos] = 0;
    }
    ans += bit[pos];
    pos -= (pos & -pos);
  }
  return ans;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    qr.push_back({x, {y, z}});
  }
  make();
  int idx = 0;
  for (auto it : qr) {
    if (it.first == 3) {
      ++idx;
      v[it.second.second].push_back({idx, {it.second.first, it.first}});
    } else
      v[it.second.second].push_back({0, {it.second.first, it.first}});
  }
  for (int i = 1; i < N; ++i) {
    ++cur;
    for (int j = 0; j < v[i].size(); ++j) {
      auto it = v[i][j];
      if (it.second.second == 1) {
        update(it.second.first, 1);
      } else if (it.second.second == 2) {
        update(it.second.first, -1);
      } else {
        ans[it.first] = get(it.second.first);
      }
    }
  }
  for (int i = 1; i <= idx; ++i) cout << ans[i] << endl;
}
void make() {
  vector<int> temp;
  map<int, int> val, tim;
  for (auto it : qr) {
    temp.push_back(it.second.second);
  }
  sort(temp.begin(), temp.end());
  for (auto it : temp) {
    if (val.find(it) == val.end()) {
      val[it] = ++tt;
    }
  }
  temp.clear();
  for (auto it : qr) {
    temp.push_back(it.second.first);
  }
  sort(temp.begin(), temp.end());
  tt = 0;
  for (auto it : temp) {
    if (tim.find(it) == tim.end()) {
      tim[it] = ++tt;
    }
  }
  temp.clear();
  for (int i = 0; i < qr.size(); ++i) {
    qr[i].second.first = tim[qr[i].second.first];
    qr[i].second.second = val[qr[i].second.second];
  }
}
