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
#include<iostream>
#include<map>
#include<utility>
using namespace std;

int main()
{
	int n; cin >> n;
	typedef pair<int,int> val;
	map<int,val> p;
	map<int,val>::iterator it;
	for(int i=0;i<n;i++)
	{
		
		int a,b,c; cin >> a >> b >> c;
		it = p.find(b-c);
		if(it == p.end())
		{
			p[b-c] = make_pair(0,0);
		}
		if(a==1)	p[b-c].first++;
		else		p[b-c].second++;
	}
	int ans =0;
	for(map<int,val>::iterator iter=p.begin(); iter!=p.end(); ++iter)
	{
		ans += min(iter->second.first,iter->second.second);
	}
	cout << ans;
	return 0;
}