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
#include <algorithm>
#include <iostream>
#include <unordered_map>

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

  int n;
  std::cin >> n;

  std::unordered_map<int, std::pair<int, int>> counts;

  for (int i = 0; i < n; ++i) {
    int r, w, t;
    std::cin >> r >> w >> t;
    if (r == 1) {
      ++counts[w - t].first;
    } else {
      ++counts[w - t].second;
    }
  }

  int ans = 0;
  for (auto &&[key, vals] : counts) {
    ans += vals.first < vals.second ? vals.first : vals.second;
  }
  std::cout << ans << std::endl;
  return 0;
}