1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<cstdio>

int n, r, w, t;
int col_h[2000200];
int col_w[2000200];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d%d%d", &r, &w, &t);
        if (r == 1) col_h[w - t + 1000000]++;
        else col_w[w - t + 1000000]++;
    }

    int ans = 0;
    for (int i = 0; i < 2000200; ++i)
    {
        if (col_h[i] == 0 || col_w[i] == 0) continue;
        ans += col_h[i] < col_w[i] ? col_h[i] : col_w[i];
    }
    printf("%d\n", ans);
}