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
#include <bits/stdc++.h>


using namespace std;


const int MAXV = 1000 * 1000;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector <vector<int>> cnt(2, vector <int> (2 * MAXV + 1, 0));

    while (n--) {
        int type, w, t;
        cin >> type >> w >> t; type--;

        cnt[type][MAXV + w - t]++;
    }

    int ans = 0;

    for (int i = 0; i <= 2 * MAXV; i++) {
        ans += min(cnt[0][i], cnt[1][i]);
    }

    cout << ans << '\n';

    return 0;
}