#include <bits/stdc++.h>
const int32_t MAX_NUM = 1e9 + 696969;
struct Vertex {
  Vertex *l, *r;
  int32_t low, high;
  int32_t val;
  Vertex() : l(nullptr), r(nullptr), low(0), high(0), val(0) {}
  Vertex(int32_t pL, int32_t pH)
      : l(nullptr), r(nullptr), low(pL), high(pH), val(0) {}
  int32_t sum(int32_t pos) {
    int32_t med = (low + high) / 2;
    if (pos >= high) {
      return val;
    } else {
      int32_t answ = 0;
      if (l != nullptr) {
        answ += l->sum(pos);
      }
      if ((r != nullptr) && (pos > med)) {
        answ += r->sum(pos);
      }
      return answ;
    }
  }
  void add(int32_t pos, int32_t pVal) {
    val += pVal;
    if (low != high) {
      int32_t med = (low + high) / 2;
      if (pos <= med) {
        if (l == nullptr) {
          l = new Vertex(low, med);
        }
        l->add(pos, pVal);
      } else {
        if (r == nullptr) {
          r = new Vertex(med + 1, high);
        }
        r->add(pos, pVal);
      }
    }
  }
};
std::map<int32_t, Vertex *> trees;
int main() {
  int32_t qCnt;
  scanf("%i", &qCnt);
  for (int32_t i = 0; i < qCnt; i++) {
    int32_t type, pos, treeInd;
    scanf("%i %i %i", &type, &pos, &treeInd);
    Vertex *cur = trees[treeInd];
    if (type == 3) {
      if (cur == nullptr) {
        printf("0\n");
      } else {
        printf("%i\n", cur->sum(pos));
      }
    } else {
      int32_t val = (type == 1) ? 1 : -1;
      if (cur == nullptr) {
        cur = new Vertex(0, MAX_NUM);
        trees[treeInd] = cur;
      }
      cur->add(pos, val);
    }
  }
}
