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
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int,int>t1,t2;
vector<int>v;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0; i<n; i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		if(t1.find(b-c)==t1.end()&&t2.find(b-c)==t2.end())
		{
			v.push_back(b-c);
		}
		if(a==1)
		{
			t1[b-c]++;
		}
		else
		{
			t2[b-c]++;
		}
	}
	int wyn=0;
	for(int i=0;i<v.size();i++)
	{
		if(t1.find(v[i])!=t1.end()&&t2.find(v[i])!=t2.end())
		{
			wyn+=min(t1[v[i]],t2[v[i]]);
		}
	}
	cout<<wyn;
    return 0;
}