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
#include <bits/stdc++.h>
#define PB push_back
using namespace std;
typedef long long int ll;
typedef vector <int> vi;
#define FOR(k,a,b) for(int k=(a); k < (b); ++k)
const int N=1000001;
ll prt = (ll)1000000007;
int main()
{
	int n;
	scanf("%d",&n);
	map <int,int> ver;
	map <int,int> hor;
	for(int i=0;i<n;i++){
		int r,w,t;
		scanf("%d %d %d",&r,&w,&t);
		if(r==1)ver[w-t]++;
		else hor[w-t]++;
	}
	int res=0;
	auto it_v = ver.begin();
	auto it_h = hor.begin();
	while(it_v != ver.end() && it_h != hor.end()){
		if(it_v->first == it_h->first){
			res+=min(it_v->second,it_h->second);
			it_v++;
			it_h++;
		}
		else if(it_v->first < it_h->first)it_v++;
		else it_h++;	
	}
	printf("%d",res);
	return 0;
}