#include <bits/stdc++.h>
using namespace std;
const long long INF = ((long long)1 << 59);
struct op {
  long long a, t, x;
};
class FenwickTree {
 private:
  vector<long long> ft;
  long long LSOne(long long S) { return (S & (-S)); }

 public:
  FenwickTree(long long n) { ft.assign(n + 1, 0); }
  long long rsq(int b) {
    long long sum = 0;
    for (; b; b -= LSOne(b)) sum += ft[b];
    return sum;
  }
  long long rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }
  void update(int k, long long v) {
    for (; k < (int)ft.size(); k += LSOne(k)) ft[k] += v;
  }
};
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<long long, map<long long, long long> > to_fenwick;
  int a, t, x;
  vector<op> ops(n);
  vector<pair<long long, long long> > value_time(n);
  for (int i = 0; i < n; i++) {
    cin >> ops[i].a >> ops[i].t >> ops[i].x;
    value_time[i] = make_pair(ops[i].x, ops[i].t);
  }
  sort(value_time.begin(), value_time.end());
  int curr = 1;
  map<long long, long long> first_num;
  first_num[value_time[0].first] = curr;
  to_fenwick[value_time[0].first][value_time[0].second] = curr++;
  for (int i = 1; i < n; ++i) {
    if (value_time[i].first != value_time[i - 1].first) {
      first_num[value_time[i].first] = curr;
    }
    to_fenwick[value_time[i].first][value_time[i].second] = curr++;
  }
  FenwickTree fenwick(100005);
  for (int i = 0; i < n; i++) {
    if (ops[i].a == 1) {
      fenwick.update(to_fenwick[ops[i].x][ops[i].t], 1);
    } else if (ops[i].a == 2) {
      fenwick.update(to_fenwick[ops[i].x][ops[i].t], -1);
    } else {
      cout << fenwick.rsq(first_num[ops[i].x], to_fenwick[ops[i].x][ops[i].t])
           << "\n";
    }
  }
  return 0;
}
