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
#include <stdio.h>
#include <map>


using namespace std;



int main()
{
	int n, r, w, t;
	map<int, int> m[2];
	map<int, int>::iterator it, it2;
	scanf("%d", &n);
	
	
	for (int i = 0; i < n; i ++)
	{
		scanf("%d %d %d", &r, &w, &t);
		r--;
		it = m[r].find(w - t);
		if (it != m[r].end())
		{
			it->second++;
		}
		else
		{
			m[r][w - t] = 1;
		}
	}

	int one = m[0].size()<m[1].size()? 0:1, two = m[0].size() < m[1].size() ? 1 : 0, sum =0;
	
	for (it = m[one].begin(); it!=m[one].end(); it++)
	{
		it2 = m[two].find(it->first);
		if (it2 != m[two].end())
		{
			sum += it2->second < it->second ? it2->second : it->second;
		}
	}


	printf("%d", sum);
}