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

int main()
{
	int n, r, w, t, total_conflicts = 0;
	scanf("%d", &n);
	std::map<int, int> deliveries_count_vertical, deliveries_count_horizontal;
	for (int i = 0; i < n; ++i)
	{
		scanf("%d %d %d", &r, &w, &t);
		if (r == 1)
			deliveries_count_vertical[w - t]++;
		else
			deliveries_count_horizontal[w - t]++;
	}

	for (auto data : deliveries_count_vertical)
	{
		const auto key = data.first;
		if (deliveries_count_horizontal.count(key))
			total_conflicts += std::min(deliveries_count_vertical[key], deliveries_count_horizontal[key]);
	}
	printf("%d\n", total_conflicts);
	return 0;
}