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

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    unordered_map<int, int> first;
    unordered_map<int, int> second;
    
    while(n--)
    {
        int r,w,t;
        cin >> r >> w >> t;
        if (r == 1) 
        {
            first[w - t] += 1;
        }
        else 
        {
            second[w - t] += 1;
        }
    }
    
    int min = 0;
    
    for (const auto& i : first) {
        auto y = second.find(i.first);
        if (y != second.end()){
            if (y->second > i.second) {
                min += i.second;
            } else {
               min += y->second;
            }
        }
    }

    cout << min;
    return 0;
}