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 <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 2'000'000;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<array<int, 2>> count(MAXN);

    for (int i = 0; i < n; i++) {
        int r, w, t;
        cin >> r >> w >> t;
        t += -w + MAXN / 2;
        count[t][r - 1]++;
    }

    int result = 0;
    for (const auto [a, b] : count) {
        result += min(a, b);
    }
    
    cout << result << "\n";
}