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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int ans=0;
vector<pii>poma,pomb;
vector<pii>x,y;
const int MAX=1e6+5;
const int STALA=1e6;
int cnt1[MAX*2],cnt2[MAX*2];
int32_t main(){
  BOOST;
  int n;
  cin>>n;
  for (int i=1;i<=n;i++){
     int type,a,b;
     cin>>type>>a>>b;
     if (type==1)poma.pb({a,b});
     else pomb.pb({a,b});
  }
  sort(poma.begin(),poma.end());
  sort(pomb.begin(),pomb.end());
  for (int i=0;i<sz(poma);i++){
    if (i==sz(poma)-1 || (poma[i].st!=poma[i+1].st || poma[i].nd!=poma[i+1].nd)){
      x.pb(poma[i]);
    }
    else ans++;
  } 
  
  for (int i=0;i<sz(pomb);i++){
    if (i==sz(pomb)-1 || (pomb[i].st!=pomb[i+1].st || pomb[i].nd!=pomb[i+1].nd)){
      y.pb(pomb[i]);
    }
    else ans++;
  }
  
  for (auto it:x)cnt1[it.st-it.nd+STALA]++;
  for (auto it:y)cnt2[it.st-it.nd+STALA]++;
  
  for (int i=0;i<MAX*2;i++)ans+=min(cnt1[i],cnt2[i]);
  
   
  cout<<ans;  
  return 0; 
}