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
57
58
#include <bits/stdc++.h>

struct P
{
	int w;
	int t;
};

std::vector<P> C[2];

int main()
{
	std::ios_base::sync_with_stdio(0);

	C[0].reserve(500000);
	C[1].reserve(500000);

	int n;
	std::cin >> n;

	for(int i=0;i<n;i++)
	{
		int type, w, t;

		std::cin >> type >> w >> t;
		type--;

		C[type].push_back({w, t});
	}

	std::unordered_map<int, int> h1, h2;

	for(int i=0;i<int(C[0].size());i++)
	{
		int c = C[0][i].w - C[0][i].t;
		h1[c]++;
	}
	for(int i=0;i<int(C[1].size());i++)
	{
		int c = C[1][i].w - C[1][i].t;
		h2[c]++;
	}

	int result = 0;

	for(auto it=h1.begin(); it!=h1.end();it++)
	{
		auto it2 = h2.find(it->first);
		if(it2 != h2.end())
		{
			result += std::min(it->second, it2->second);
		}
	}

	std::cout << result << "\n";

	return 0;
}