#include <bits/stdc++.h>
using namespace std;
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
};
template <class A, class B>
ostream &operator<<(ostream &os, pair<A, B> p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, rge<T> d) {
  os << "[";
  for (auto it = d.b; it != d.e; it++) os << (it == d.b ? "" : ", ") << *it;
  return os << "]";
}
struct segtree {
  int l, r;
  long long sum;
  segtree *left, *right;
  segtree(int l, int r, long long v = 0)
      : l(l), r(r), sum(v), left(0), right(0) {}
  void pull() {
    sum = 0;
    if (left) sum += left->sum;
    if (right) sum += right->sum;
  }
  void update(int p, long long v) {
    if (l == r) {
      sum += v;
      return;
    }
    int m = (l + r) / 2;
    if (p <= m) {
      if (!left) left = new segtree(l, m);
      left->update(p, v);
    } else {
      if (!right) right = new segtree(m + 1, r);
      right->update(p, v);
    }
    pull();
  }
  long long qsum(int ll, int rr) {
    if (rr < l || r < ll) return 0;
    if (ll <= l && r <= rr) return sum;
    int m = (l + r) / 2;
    long long sumx = 0;
    if (left) sumx += left->qsum(ll, rr);
    if (right) sumx += right->qsum(ll, rr);
    return sumx;
  }
};
enum { add = 1, rem, count };
map<int, segtree *> st;
int q;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  cin >> q;
  int type, timer, x;
  while (q--) {
    cin >> type >> timer >> x;
    if (!st.count(x)) st[x] = new segtree(1, 1e9);
    if (type == add || type == rem) {
      st[x]->update(timer, type == add ? +1 : -1);
    } else {
      cout << st[x]->qsum(1, timer) << '\n';
    }
  }
  return 0;
}
