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
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n, r, w, t;

    cin >> n;

    vector<vector<int>> delivery(2, vector<int>(2000001));

    for (int i = 0; i < n; i++)
    {
        cin >> r >> w >> t;
        delivery[r - 1][w - t + 1000000]++;    }

    int cancelCount = 0;

    for (int i = 0; i < 2000001; i++)
    {
        cancelCount += min(delivery[0][i], delivery[1][i]);
    }

    cout << cancelCount << endl;
}