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

using namespace std;

int main() {
	map<int, int> values[2];
	
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		int a, b, c;
		cin >> a >> b >> c;
		++values[a-1][b-c];
	}
	
	int res = 0;
	for(auto el: values[0]) {
		res += min(el.second, values[1][el.first]);
	}
	
	cout << res << endl;
	
	return 0;
}