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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
/*typedef struct {
    int type;
    int start;
    int time;
    vector<int> collisions;
}car;*/

int main() {
    int n;
    cin >> n;
    map<int,int> a;
    map<int,int> b;
    int type,start,time;
    for (int i = 0; i < n; i++)
    {
        cin >> type>>start>>time;
        if (type == 1)
            a[start - time]++;
        else
            b[start - time]++;
    }
    int to_remove=0;
    for (auto &i:a)
    {
        if (b[i.first]>0) {
            to_remove += min(i.second, b[i.first]);
        }
    }
    cout << to_remove;
    /*sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    vector<int> v(a.size() + b.size());
    vector<int>::iterator it, st;
    it = set_intersection(a.begin(),a.end(),b.begin(),b.end(),v.begin());
    for (st = v.begin(); st != it; ++st)
        cout << *st << ", ";*/

    return 0;
}