1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
const ll maxN = 1e6;
int tab[2*maxN+3][3];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();
    int i;
    int n;
    cin>>n;
    for (i = 0; i < n; i++){
        int type,x,delay;
        cin>>type>>x>>delay;
        x += maxN-delay;
        tab[x][type]++;
    }
    int wy = 0;
    for (i = 0; i < 2*maxN+3; i++) wy += min(tab[i][1],tab[i][2]);
    cout<<wy<<"\n";
    return 0;
}