1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    int n, r, w, t;
    unordered_map<int, int> mp1,mp2;
    
    cin >> n;
    while(n--) {
        cin >> r >> w >> t;
        if(r==1) mp1[w-t]++;
        else mp2[w-t]++;
    }

    int res=0;
    for(auto &kv: mp1)
        res += min(kv.second, mp2[kv.first]);
        
    cout << res << endl;

    return 0;
}