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
#include <cstdio>
#define MAX 1000000
int data[2][2 * MAX + 7];

int main() {
    int n;
    int a, x, t;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &a, &x, &t);
        data[a - 1][MAX + x - t]++;
    }

    int result = 0;

    for (int i = 0; i <= 2 * MAX; i++) {
        int min = data[0][i];
        if (data[1][i] < min) min = data[1][i];

        result += min;
    }

    printf("%d\n", result);

    return 0;
}