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
#include <cstdio>
#include <algorithm>

const int max_val = 2000100;

int A[max_val];
int B[max_val];
int n;

int main() {
    for (int i = 0; i < max_val; ++i) A[i] = B[i] = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int a, w, t;
        scanf("%d %d %d", &a, &w, &t);
        if (a == 1) ++A[w - t + 1000000];
        else ++B[w - t + 1000000];
    }
    int res = 0;
    for (int i = 0; i < max_val; ++i) {
        res += std::min(A[i], B[i]);
    }
    printf("%d\n", res);
    return 0;
}