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
#include <bits/stdc++.h>

using namespace std;

struct Count {
   int c[2];
   Count() : c{0, 0} {}
   int V() { return min(c[0], c[1]); }
};

unordered_map<int, Count> a;

int main() {
   int n;
   scanf("%d", &n);
   for (int i = 0; i < n; i++) {
      int r, w, t;
      scanf("%d%d%d", &r, &w, &t);
      a[w - t].c[r - 1]++;
   }
   int res = 0;
   for (auto c : a) res += c.second.V();
   printf("%d\n", res);
   return 0;
}