1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <bits/stdc++.h>
using namespace std;

unordered_map<int, pair<int, int>> cnt;

int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int r, w, t;
    scanf("%d %d %d", &r, &w, &t);
    auto& p = cnt[w - t];
    if (r == 1) {
      p.first++;
    } else {
      p.second++;
    }
  }
  int res = 0;
  for (auto const& it : cnt) {
    res += min(it.second.first, it.second.second);
  }
  printf("%d\n", res);
}