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

using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	map<int, pair<int, int>> sums;
	int r, w, t;
	for (int i = 0; i < n; i++) {
		scanf("%d%d%d", &r, &w, &t);
		if (r == 1) sums[w - t].first++;
		else sums[w - t].second++;
	}
	int ans = 0;
	for (auto x : sums) {
		if (x.second.first >= 1 && x.second.second >= 1)
			ans += min(x.second.first, x.second.second);
	}

	printf("%d", ans);

	return 0;
}