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
#include<bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pil = pair<int, long long>;
using pli = pair<long long, int>;
using ll = long long;
#define X first
#define Y second
#define pb push_back
#define mp make_pair
int n,r,w,t, a[2000007], b[2000007], wyn;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i<=n; i++){
        cin >> r >> w >> t;
        if(r==1) a[w-t+1000000]++;
        else b[w-t+1000000]++;
    }
    for(int i = 0; i<=2000000; i++){
        wyn=wyn+min(a[i],b[i]);
    }
    cout << wyn;
    return 0;
}