1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<cstdio>
#include<algorithm>

#define MAXN 500003
#define MAXWT 2000003

int n, r, w, t;
int ile[2][MAXWT];
int ile_max = 0;

int main () {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
	  scanf("%d %d %d", &r, &w, &t);
	  ile[r-1][t-w+1000000]++;
  }
  
  for (int i = 0; i < MAXWT; i++) {
	  ile_max += std::max(ile[0][i], ile[1][i]);
  }
  printf("%d\n", n - ile_max);

  return 0;
}