1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

const int z = 1e6*2;
int h[z*2+1];
int w[z*2+1];

int main() {
    int n, a, b, c, res = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a >> b >> c;
        if(a == 1) h[z+b-c]++;
        else w[z+b-c]++;
    }
    for (int i = 0; i < z*2+1; i++) res+=min(w[i], h[i]);
    cout << res << endl;
}