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
#include <cstdio>
#include <map>

using namespace std;

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

}