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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<pair<int, int>> cars;
    for(int i = 0; i < n; i++){
        int r, w, t;
        cin>>r>>w>>t;
        cars.push_back({w-t, r});
    }
    sort(cars.begin(), cars.end());
    vector<tuple<int, int, int>> counted;
    int cnt = 1;
    for(int i = 1; i < n; i++){
        if(cars[i-1] == cars[i]){
            cnt++;
        }else{
            counted.push_back(make_tuple(cars[i-1].first, cars[i-1].second, cnt));
            cnt = 1;
        }
    }
    counted.push_back(make_tuple(cars[n-1].first, cars[n-1].second, cnt));
    /*for(auto t : counted){
        int x = get<0>(t), y = get<1>(t), z = get<2>(t);
        cout<<x<<" "<<y<<" "<<z<<"\n";
    }*/
    int result = 0;
    for(int i = 1; i < counted.size(); i++){
        if(get<0>(counted[i]) == get<0>(counted[i-1])){
            result += min(get<2>(counted[i]), get<2>(counted[i-1]));
        }
    }
    cout<<result;
    return 0;
}