#include <bits/stdc++.h>   using namespace std;   template <typename _T>   void read(_T &x) {     _T f = 1;     x = 0;     char s = getchar();     while (s >  9  || s <  0 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while ( 0  <= s && s <=  9 ) {       x = (x << 3) + (x << 1) + (s ^ 48);       s = getchar();     }     x *= f;   }   struct ming {     long long typ, t, x, id, pos;   } a[100010];   long long n, ans[100010], num[100010];   vector<long long> vec;   long long cmp1(const ming &a, const ming &b) { return a.t < b.t; }   long long cmp2(const ming &a, const ming &b) { return a.id < b.id; }   void merge(long long l, long long r) {     if (l == r) return;     long long mid = l + r >> 1, j = l;     merge(l, mid);     merge(mid + 1, r);     sort(a + l, a + mid + 1, cmp1);     sort(a + mid + 1, a + r + 1, cmp1);     for (long long i = mid + 1; i <= r; i++) {       while (j <= mid && a[j].t <= a[i].t) num[a[j].pos] += a[j].typ, j++;       if (!a[i].typ) ans[a[i].id] += num[a[i].pos];     }     for (long long i = l; i < j; i++) num[a[i].pos] -= a[i].typ;   }   signed main() {     read(n);     for (long long i = 1; i <= n; i++) {       read(a[i].typ);       read(a[i].t);       read(a[i].x);       if (a[i].typ == 2) a[i].typ = -1;       if (a[i].typ == 3) a[i].typ = 0;       a[i].id = i;       vec.push_back(a[i].x);     }     sort(vec.begin(), vec.end());     vec.erase(unique(vec.begin(), vec.end()), vec.end());     for (long long i = 1; i <= n; i++)       a[i].pos = lower_bound(vec.begin(), vec.end(), a[i].x) - vec.begin() + 1;     merge(1, n);     sort(a + 1, a + n + 1, cmp2);     for (long long i = 1; i <= n; i++)       if (!a[i].typ) printf( %lld n , ans[i]);     return 0;   }   