#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const int N = 1000 * 1000;
int n;
int m;
vector<pair<int, pair<int, int> > > q[N + 1];
pair<int, int> v[N + 1];
int o;
unordered_map<int, int> num;
int f[N + 1];
int res[N + 1];
int getx(int x) {
  if (num.count(x)) return num[x];
  num[x] = o++;
  return o - 1;
}
int getf(int x) {
  int y = 0;
  while (x > 0) {
    y += f[x];
    x = (x & (x + 1)) - 1;
  }
  return y;
}
void add(int x, int y, int n) {
  while (x <= n) {
    f[x] += y;
    x |= x + 1;
  }
}
string get(int x) {
  string s = "";
  if (x == 0) s = "0";
  while (x) {
    s = s + char(x % 10 + '0');
    x /= 10;
  }
  reverse((s).begin(), (s).end());
  return s;
}
char h[100];
char *ch;
int read() {
  int x = 0;
  while (!(*ch >= '0' && *ch <= '9')) ch++;
  while (*ch >= '0' && *ch <= '9') {
    x = x * 10 + (*ch) - '0';
    ch++;
  }
  return x;
}
int main() {
  scanf("%d", &n);
  gets(h);
  for (int i = 0; i < n; i++) {
    int a, t, x;
    gets(h);
    ch = h;
    a = read();
    t = read();
    x = read();
    x = getx(x);
    q[x].push_back(make_pair(i, make_pair(a, t)));
    res[i] = -1e9;
  }
  for (int i = 0; i < o; i++) {
    int len = ((int)(q[i]).size());
    for (int j = 0; j < len; j++) v[j] = make_pair(q[i][j].second.second, j);
    sort(v, v + len);
    for (int j = 0; j < len; j++) q[i][v[j].second].second.second = j + 1;
    for (int j = 1; j <= len; j++) f[j] = 0;
    for (int j = 0; j < len; j++)
      if (q[i][j].second.first == 1)
        add(q[i][j].second.second, 1, len);
      else if (q[i][j].second.first == 2)
        add(q[i][j].second.second, -1, len);
      else
        res[q[i][j].first] = getf(q[i][j].second.second);
  }
  string ans = "";
  bool f = true;
  for (int i = 0; i < n; i++)
    if (res[i] >= -1e8) {
      if (!f) ans += "\n";
      f = false;
      ans += get(abs(res[i]));
    }
  puts(ans.c_str());
  return 0;
}
