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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define MAXN 100001

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;

	int c = 0;
	vi C[2];
	map<int, int> M;
	
	int magic_number, r, w, t;
	for(int i=0; i<n; i++) {
		cin>>r>>w>>t;
		
		magic_number = w - t;
		if(M.find(magic_number) == M.end()) {
			C[0].pb(0);
			C[1].pb(0);
			M[magic_number] = c;
			c++;
		}
		C[r-1][M[magic_number]]++;
	}

	int res = 0;
	for(int i=0; i<c; i++)
		res += min(C[0][i], C[1][i]);
	
	cout<<res<<endl;

	return 0;
}