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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
using namespace std;

pair<int, int> convert_point(int r, int w, int t) {
    if (r == 1) return {-t, w};
    if (r == 2) return {w, -t};
    assert(false);
}

int c(pair<int, int> p) {
    return p.first + p.second;
}

int ptype(pair<int, int> p) {
    if (p.first <= 0 && p.second > 0) return 0;
    if (p.first > 0 && p.second <= 0) return 1;
    assert(false);
}

unordered_map<int, pair<int, int>> cnt;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie();
    cout.tie();

    int n;
    cin >> n;
    for (int r, w, t, i = 0; i < n; i++) {
        cin >> r >> w >> t;
        auto p = convert_point(r, w, t);
        if (cnt.find(c(p)) == cnt.end()) {
            cnt[c(p)] = {0, 0};
        }
        if (ptype(p) == 0) {
            cnt[c(p)].first++;
        } else {
            cnt[c(p)].second++;
        }
    }
    int res = 0;

    for (auto kv : cnt) {
        res += min(kv.second.first, kv.second.second);
    }

    cout << res;
    return 0;
}