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
#include<iostream>
#include<map>

#define N 1000000

using namespace std;

int a[2 * N + 1][2];
int r, w, t, n;

int main() {
  ios_base::sync_with_stdio(0);

  cin >> n;
  while (n--) {
    cin >> r >> w >> t;
    a[w - t + N][r - 1]++;
  }

  int res = 0;
  for (int i = 0; i < 2 * N + 1; i++) {
    res += min(a[i][0], a[i][1]);
  }
  cout << res << endl;

  return 0;
}