1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <bits/stdc++.h>
using namespace std;
#define PLI pair<long long, int>

int diff[2000005][3];

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int r,w,t;
        cin>>r>>w>>t;
        diff[w-t+(int)1e6+1][r]++;
    }
    int res=0;
    for(int i=0;i<=2e6+2;i++)res+=min(diff[i][1],diff[i][2]);
    cout<<res<<endl;
}