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
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <unordered_map>
using namespace std;

void solve()
{
    int n;
    cin >> n;
    unordered_map<int, int> det_x{};
    unordered_map<int, int> det_y{};
    for (int i = 0; i < n; i++)
    {
        int r, w, t;
        cin >> r >> w >> t;
        if (r == 1)
        {
            det_x[w - t]++;
        }
        else
        {
            det_y[w - t]++;
        }
    }
    int ans = 0;
    for (auto p : det_x)
    {
        int key = p.first;
        int val = p.second;
        if (det_y.find(key) != det_y.end())
        {
            ans += min(val, det_y[key]);
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}