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
28
29
30
31
32
#include <algorithm>
#include <iostream>
#include <unordered_map>

int main() {
  std::ios::sync_with_stdio(0);

  int n;
  std::cin >> n;

  std::unordered_map<int, int> ver, hor;

  int r, l, t;
  while (n--) {
    std::cin >> r >> l >> t;
    if (r == 1) {
      ver[t - l]++;
    }
    else {
      hor[t - l]++;
    }
  }

  int total = 0;
  for (auto [time, count] : ver) {
    total += std::min(count, hor[time]);
  }

  std::cout << total << std::endl;

  return 0;
}