#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  int m = 1;
  for (int i = 0; i < m; i++) {
    solve();
  }
  return 0;
}
long long INF = INT64_MAX;
long long mod = 1000000007LL;
vector<vector<long long>> g;
vector<long long> used;
set<long long> cur;
bool flag;
void solve() {
  long long n;
  cin >> n;
  vector<long long> ans(n, -1);
  vector<long long> a(n), tt(n), type(n);
  map<long long, set<long long>> group;
  for (long long i = 0; i < n; i++) {
    cin >> type[i] >> tt[i] >> a[i];
    group[a[i]].insert(i);
  }
  for (auto iter = group.begin(); iter != group.end(); ++iter) {
    set<long long> cur = iter->second;
    map<long long, long long> coor1, coor;
    for (auto it = cur.begin(); it != cur.end(); ++it) {
      coor1[tt[*it]]++;
    }
    long long sz = 2;
    for (auto it = coor1.begin(); it != coor1.end(); ++it) {
      coor[it->first] = sz;
      sz++;
    }
    vector<long long> t(sz * 4 + 1);
    long long k = 1;
    while (k <= sz) k *= 2LL;
    for (auto it = cur.begin(); it != cur.end(); ++it) {
      long long id = *it;
      long long time = coor[tt[id]];
      if (type[id] == 1) {
        long long r = k + time;
        t[r]++;
        while (r) {
          r /= 2;
          t[r] = t[2 * r] + t[2 * r + 1];
        }
      }
      if (type[id] == 2) {
        long long r = k + time;
        t[r]--;
        while (r) {
          r /= 2;
          t[r] = t[2 * r] + t[2 * r + 1];
        }
      }
      if (type[id] == 3) {
        long long r = k + time;
        long long l = k;
        long long sum = 0;
        while (l < r) {
          long long l1 = l / 2;
          long long r1 = r / 2;
          if (l1 * 2 == l - 1) {
            sum -= t[l - 1];
          }
          if (r1 * 2 + 1 == r + 1) {
            sum -= t[r + 1];
          }
          l = l1;
          r = r1;
        }
        sum += t[l];
        ans[id] = sum;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    if (ans[i] != -1) {
      cout << ans[i] << endl;
    }
  }
}
