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
#include <iostream>
#include <map>
#include <algorithm>

int main() {
	int n;
	std::cin >> n;

	std::map<int, int> m1;
	std::map<int, int> m2;

	int r, w, t;
	for (int i = 0; i < n; i++) {
		std::cin >> r >> w >> t;
		if (r == 1)
			m1[w-t]++;
		else
			m2[w-t]++;
	}

	int res = 0;
	for (auto const&[k1, v1]: m1) {
		res += std::min(v1, m2[k1]);
	}

	std::cout << res << std::endl;
	return 0;
}