1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// mrozik[@]gmail

#include <cstdio>
#include <algorithm>
using namespace std;

int crash[2][2'000'001] {};

int main() {
  int N; scanf("%d", &N);

  for (int i = 0; i < N; i++) {
    int r, w, t; scanf("%d%d%d", &r, &w, &t);
    crash[r-1][999'999 + w - t]++;
  }

  int result = 0;
  for (int i = 0; i < 2'000'001; i++) {
    result += min(crash[0][i], crash[1][i]);
  }

  printf("%d\n", result);
  return 0;
}