#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
const int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int Mod = 998244353;
const long double Pi = acos(-1);
const long long int Inf = 4e18;
const long double Eps = 1e-9;
int dx[9] = {0, 1, -1, 0, 0, 1, 1, -1, -1};
int dy[9] = {0, 0, 0, 1, -1, 1, -1, 1, -1};
using namespace std;
struct Vertex {
  long long int lb, ub, sum;
  Vertex *right, *left;
};
struct SegmentTree {
  Vertex* root = new Vertex;
  void Initialize() {
    root->lb = 0;
    root->ub = 1000000000;
    root->sum = 0;
    root->right = NULL;
    root->left = NULL;
  }
  Vertex* Extend(long long int l, long long int r) {
    Vertex* new_node = new Vertex;
    new_node->lb = l;
    new_node->ub = r;
    new_node->sum = 0;
    new_node->left = NULL;
    new_node->right = NULL;
    return new_node;
  }
  void Update(long long int idx, long long int x, Vertex* cur) {
    if (cur->lb == cur->ub)
      cur->sum += x;
    else {
      long long int tm = (cur->lb + cur->ub) / 2;
      if (idx <= tm) {
        if (cur->left == NULL) {
          cur->left = Extend(cur->lb, tm);
        }
        Update(idx, x, cur->left);
      } else {
        if (cur->right == NULL) {
          cur->right = Extend(tm + 1, cur->ub);
        }
        Update(idx, x, cur->right);
      }
      cur->sum = 0;
      if (cur->left) cur->sum += cur->left->sum;
      if (cur->right) cur->sum += cur->right->sum;
    }
  }
  long long int Sum(long long int l, long long int r, Vertex* cur) {
    if (l <= cur->lb && cur->ub <= r)
      return cur->sum;
    else {
      long long int tm = (cur->lb + cur->ub) / 2;
      if (r <= tm) {
        if (cur->left == NULL)
          return 0;
        else
          return Sum(l, r, cur->left);
      } else if (l > tm) {
        if (cur->right == NULL)
          return 0;
        else
          return Sum(l, r, cur->right);
      } else {
        long long int z = 0;
        if (cur->left) {
          z += Sum(l, tm, cur->left);
        }
        if (cur->right) {
          z += Sum(tm + 1, r, cur->right);
        }
        return z;
      }
    }
  }
};
void TestCase() {
  long long int n;
  cin >> n;
  map<long long int, SegmentTree> m;
  while (n--) {
    long long int a, t, x;
    cin >> a >> t >> x;
    if (a == 1) {
      if (m.find(x) == m.end()) {
        SegmentTree sgmt;
        sgmt.Initialize();
        m[x] = sgmt;
      }
      m[x].Update(t, 1, m[x].root);
    } else if (a == 2) {
      m[x].Update(t, -1, m[x].root);
    } else {
      if (m.find(x) != m.end())
        cout << m[x].Sum(0, t, m[x].root) << "\n";
      else
        cout << 0 << "\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  int T = 1;
  while (T--) {
    TestCase();
  }
  return 0;
}
