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
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;


int main() {
  int n;
	scanf("%d",&n);
	vector<pair<int,int> > a(n);
	for (int i = 0; i < n; i++) {
		int r,w,t;
		scanf("%d %d %d",&r,&w,&t);
		a[i].first = w-t;
		a[i].second = r;
	}
	sort(a.begin(), a.end());
	int ret = 0;
	for (int i = 0; i < n; ) {
	  int j = i, A = 0, B = 0;
		while (j < n && a[j].first == a[i].first) {
		  if (a[j].second == 1) A++;
			else B++;
			j++;
		}
		i = j;
		//printf("%d %d\n", A, B);
		ret += min(A, B);
	}
	printf("%d\n",ret);
	return 0;
}