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 <bits/stdc++.h>
using namespace std;

const int MAX_W = 2 * 1000 * 1000 + 1;
int main() {
  int n;
  cin >> n;
  vector <int> horizontal(MAX_W);
  vector <int> vertical(MAX_W);
  for (int i = 0; i < n; i++) {
    int r, w, t;
    cin >> r >> w >> t;
    if (r == 1) {
        horizontal[w - t + 1000 * 1000]++;
    } else { // r == 2
        vertical[w - t + 1000 * 1000]++;
    }
  }
  int res = 0;
  for (int i = 0; i < MAX_W; i++) {
      if (horizontal[i] > 0 && vertical[i] > 0) {
          res += min(horizontal[i], vertical[i]);
      }
  }
  cout << res << endl;
  return 0;
}