#include <bits/stdc++.h>
using namespace std;
struct Q {
  int t, x, id;
  bool operator<(const Q& q) const { return x < q.x; }
};
const int maxn = 1000500;
int n;
vector<Q> qs[maxn];
int shr[maxn], k;
pair<int, Q> a[maxn];
int res[maxn];
void scan() {
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) {
    int a, t, x;
    scanf("%d%d%d", &a, &t, &x);
    if (a == 1)
      a = 1;
    else if (a == 2)
      a = -1;
    else
      a = 0;
    ::a[i] = {x, Q{a, t, i}};
    shr[i] = x;
  }
  sort(shr, shr + n);
  k = unique(shr, shr + n) - shr;
  for (int i = 0; i < (int)(n); ++i) {
    int x = lower_bound(shr, shr + k, a[i].first) - shr;
    qs[x].push_back(a[i].second);
  }
}
int s1[maxn], k1;
int fen[maxn];
void fadd(int i, int delta) {
  for (; i < k1 + 100; i |= (i + 1)) {
    fen[i] += delta;
  }
}
int fget(int i) {
  int s = 0;
  for (; i >= 0; i = (i & (i + 1)) - 1) {
    s += fen[i];
  }
  return s;
}
void solve() {
  memset(res, -1, sizeof res);
  for (int x = 0; x < (int)(k); ++x) {
    k1 = 0;
    for (Q q : qs[x]) {
      s1[k1++] = q.id;
    }
    sort(s1, s1 + k1);
    k1 = unique(s1, s1 + k1) - s1;
    assert(k1 == (int)qs[x].size());
    for (int i = 0; i < (int)(k1); ++i) fen[i] = 0;
    sort((qs[x]).begin(), (qs[x]).end());
    for (Q q : qs[x]) {
      int pos = lower_bound(s1, s1 + k1, q.id) - s1;
      if (q.t == 0) {
        res[q.id] = fget(pos);
      } else {
        fadd(pos, q.t);
      }
    }
  }
  for (int i = 0; i < (int)(n); ++i)
    if (res[i] != -1) {
      printf("%d\n", res[i]);
    }
}
int main() {
  scan();
  solve();
  return 0;
}
