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
#include <bits/stdc++.h>
#define fi first
#define sc second
#define forn(i,p,k) for(int i=(p);i<=(k);++i)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MM=2500013,sh=1000100;
int V[MM],H[MM];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,r,w,t;
    cin>>n;
    forn(i,1,n)
    {
        cin>>r>>w>>t;
        if(r==1)    V[w+sh-t]++;
        else        H[w+sh-t]++;
    }
    int wyn=0;
    forn(i,0,MM-1)  wyn+=min(V[i],H[i]);
    return cout<<wyn<<"\n",0;
}