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

//g++ -O3 -static 3C/3C.cpp -std=c++11 -o 3C/3c
/*
4
1 5 2
2 3 0
2 3 6
1 7 4
*/

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> mp[2];
    for(int i = 0; i < n; i++){
        int r, w, t;
        cin >> r >> w >> t;
        if(mp[r-1].count(w - t)){
            mp[r-1][w-t] ++;
        }else{
            mp[r-1].insert({w - t, 1});
        }
    }
    map<int, int>::iterator it1 = mp[0].begin(), it2 = mp[1].begin();
    int del = 0;
    while(it1 != mp[0].end() && it2 != mp[1].end()){
        if(it1->first < it2->first){
            it1 ++;
        }
        else if(it1->first > it2->first){
            it2 ++;
        }else{
            del += min(it1->second, it2->second);
            it1 ++;
            it2 ++;
        }
    }
    cout<<del;
    return 0;
}