#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX / 2, NINF = INT_MIN / 2;
const long double PI = acos(-1.0);
void prepareIO() {
  if (strlen("") != 0) {
    freopen(
        ""
        ".in",
        "r", stdin);
    freopen(
        ""
        ".out",
        "w", stdout);
  }
}
void debout() {}
template <typename Head, typename... Tail>
void debout(Head H, Tail... T) {}
class Timer {
 public:
  double begin;
  Timer() : begin(clock()) {}
  ~Timer() {
    fprintf(stderr, "%.6lf\n", (clock() - begin + .0) / CLOCKS_PER_SEC);
  }
} timer_;
void solve1();
int main() {
  prepareIO();
  solve1();
  return 0;
}
struct Fenwick {
  vector<int> tree, Time;
  int timer = 0;
  Fenwick(size_t n) {
    tree.resize(n);
    Time.resize(n);
  }
  int& getter(int index) {
    if (Time[index] != timer) {
      tree[index] = 0;
      Time[index] = timer;
    }
    return tree[index];
  }
  int get(int t) {
    int res = 0;
    for (; t >= 0; t = (t & (t + 1)) - 1) res += getter(t);
    return res;
  }
  void add(int t, int delta) {
    for (; t < (int)tree.size(); t = t | (t + 1)) getter(t) += delta;
  }
  void clear() { ++timer; }
};
void solve1() {
  ios_base::sync_with_stdio(false);
  int n;
  scanf("%d", &n);
  vector<vector<vector<int>>> v(n);
  unordered_map<int, int> m1;
  int cnt = 0;
  unordered_map<int, int> m2;
  int cnt2 = 0;
  m1.reserve(1000000);
  m2.reserve(1000000);
  vector<int> tt(n);
  for (int i = 0; i < n; i++) {
    int type, time, x;
    scanf("%d %d %d", &type, &time, &x);
    if (m1.count(x) == 0) {
      m1[x] = cnt;
      ++cnt;
    }
    tt[i] = time;
    v[m1[x]].push_back({i, type, time});
  }
  sort(tt.begin(), tt.end());
  m2[tt[0]] = 0;
  ++cnt2;
  for (int i = 1; i < n; i++) {
    if (tt[i] != tt[i - 1]) {
      m2[tt[i]] = cnt2++;
    }
  }
  vector<pair<int, int>> ans;
  Fenwick fenw(n + 10);
  for (int i = 0; i < cnt; i++) {
    for (auto& vec : v[i]) {
      if (vec[1] == 3) {
        pair<int, int> a = {vec[0], -1};
        a.second = fenw.get(m2[vec[2]]);
        ans.push_back(a);
      } else {
        int d = vec[1] == 1 ? 1 : -1;
        fenw.add(m2[vec[2]], d);
      }
    }
    fenw.clear();
  }
  sort(ans.begin(), ans.end());
  for (auto& p : ans) {
    printf("%d\n", p.second);
  }
}
