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

const int N = 2e6 + 10;

int cnt[2][N];

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);
    cnt[r - 1][w - t + 1000000]++;
  }
  int ret = 0;
  for (int i = 0; i < N; ++i) {
    ret += std::min(cnt[0][i], cnt[1][i]);
  }
  printf("%d\n", ret);
  return 0;
}