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
#include <cstdio>
#include <unordered_map>

const int C = 1000005;

using namespace std;

int main() {
  int n; scanf("%d", &n);
  unordered_map<int, int> m1, m2;
  for (int i=0; i<n; ++i) {
    int r, w, t; scanf("%d %d %d", &r, &w, &t);
    if (r == 1) {
      m1[w-t]++;
    } else {
      m2[w-t]++;
    }
  }

  int result = 0;
  for (auto e1 : m1) {
    auto e2 = m2.find(e1.first);
    if (e2 == m2.end()) continue;
    result += min(e1.second, e2->second);
  }
  printf("%d\n", result);
  return 0;
}