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

int main() {
    int N;
    int result = 0;
    std::unordered_map<int, int> cnt[2];

    scanf("%d", &N);
    for (int i=0; i<N; ++i) {
        int r, w, t;
        scanf("%d %d %d", &r, &w, &t);

        cnt[r%2][w-t]++;
    }

    for (const auto &x : cnt[0]) {
        result += std::min(x.second, cnt[1][x.first]);
    }

    printf("%d\n", result);
    return 0;
}