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
28
29
30
31
32
33
34
#include <iostream>
#include <set>
#include <map>

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;

    std::set<std::tuple<int, int, int>> S;
    std::map<int, int> A, B;

    int ret = 0;

    for (int i = 0; i < n; ++i) {
        int r, w, t;
        std::cin >> r >> w >> t;
        if (S.find(std::make_tuple(r, w, t)) != S.end()) ret++;
        else {
            S.insert(std::make_tuple(r, w, t));
            if (r == 1) A[w - t]++;
            else B[w - t]++;
        }
    }

    for (auto [x, _] : A) {
        ret += std::min(A[x], B[x]);
    }

    std::cout << ret;

    return 0;
}