#include <bits/stdc++.h>
using namespace std;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
constexpr double pi = 3.14159265358979323846264338327950288419716939937511;
constexpr double eps = 1e-9;
char ch_ch_ch[1 << 20];
inline string gs() {
  scanf("%s", ch_ch_ch);
  return string(ch_ch_ch);
}
inline string gl() {
  gets(ch_ch_ch);
  return string(ch_ch_ch);
}
inline int gi() {
  int x;
  scanf("%d", &x);
  return x;
}
using Q = pair<int, pair<int, int>>;
vector<Q> queries;
vector<Q> ordered_queries;
bool comp(const Q& lhs, const Q& rhs) { return lhs.first < rhs.first; }
map<pair<int, int>, int> answers;
vector<int> times;
int ftree[1000100];
int fsize;
void FenwInc(int i, int inc) {
  i++;
  for (; i < fsize; i = (i | (i + 1))) ftree[i] += inc;
}
int FenwSum(int r) {
  r++;
  int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += ftree[r];
  return result;
}
void solve() {
  int n = gi();
  for (auto i = (0); i < (n); ++i) {
    int q = gi();
    int t = gi();
    int num = gi();
    queries.push_back(make_pair(num, make_pair(t, q)));
  }
  ordered_queries = queries;
  stable_sort(queries.begin(), queries.end(), comp);
  int start = 0;
  while (start < (int)queries.size()) {
    int number = queries[start].first;
    int end = start + 1;
    while (end < (int)queries.size() && queries[end].first == number) {
      ++end;
    }
    int q_count = end - start;
    fsize = q_count + 5;
    for (auto i = (0); i < (fsize); ++i) ftree[i] = 0;
    times.clear();
    for (auto i = (start); i < (end); ++i)
      times.push_back(queries[i].second.first);
    sort(times.begin(), times.end());
    for (auto qit = (start); qit < (end); ++qit) {
      int t = queries[qit].second.first;
      int op = queries[qit].second.second;
      int time_point =
          lower_bound(times.begin(), times.end(), t) - times.begin();
      if (op == 1)
        FenwInc(time_point, 1);
      else if (op == 2)
        FenwInc(time_point, -1);
      else {
        int res = FenwSum(time_point);
        answers[make_pair(number, t)] = res;
      }
    }
    start = end;
  }
  for (Q q : ordered_queries) {
    int number = q.first;
    int t = q.second.first;
    int op = q.second.second;
    if (op == 3) {
      printf("%d\n", answers[make_pair(number, t)]);
    }
  }
}
int main() {
  solve();
  return 0;
}
