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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;

#define debug if(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define MAXN 500005

int n, r, w, t, wynik;

int shift = 1000000;
int ilepion[2000005], ilepoz[2000005];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {
        cin >> r >> w >> t;
        if (r == 1) {
            ++ilepoz[t - w + shift];
        } else {
            ++ilepion[t - w + shift];
        }
    }

    for (int i = 0; i <= 2 * shift + 1; ++i) {
        wynik += min(ilepoz[i], ilepion[i]);
    }
    
    printf ("%d\n", wynik);

    return 0;
}
/*
4
1 5 2
2 3 0
2 3 6
1 7 4
*/