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
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define pii pair<ll, ll>
#define pll pair<long long, long long>
#define ll long long
#define vi vector<ll>
#define vl vector<ll>
#define rep(i,p,k) for(ll i=p; i<k; i++)
#define per(i,p,k) for (ll i=k-1;i>=p;i--)

ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}

using namespace std;

int tab1[3000000];
int tab2[3000000];

int mx = 1000000;

int main() {
    int n;
    cin >> n;
    rep(i, 0, n) {
        int type, w, t;
        cin >> type >> w >> t;
        if(type == 1)
            tab1[mx+w-t]++;
        else
            tab2[mx+w-t]++;
    }
    int wyn = 0;
    rep(i, 0, 3*mx)
        wyn += min(tab1[i], tab2[i]);
    cout<<wyn;
}