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
33
34
35
#include <cstdio>
#include <set>
#include <map>
#include <utility>

int n;
int result;

std::map<int, int> posToCountByColor[2];

int main() {
  scanf("%d\n", &n);
  for (int i=0; i<n; i++) {
    int r, w, t;
    scanf("%d %d %d\n", &r, &w, &t);
    r--;
    int pos = w - t;
    if (posToCountByColor[r].find(pos) != posToCountByColor[r].end()) {
      posToCountByColor[r][pos] ++;
    } else {
      posToCountByColor[r][pos] = 1;
    }
  }
  for (auto e : posToCountByColor[0]) {
    int x = e.first;
    if (posToCountByColor[1].find(x) != posToCountByColor[1].end()) {
      int c1 = posToCountByColor[0][x];
      int c2 = posToCountByColor[1][x];
 //     printf("%d %d %d\n", x, c1, c2);
      result += std::min(c1, c2);
    }
  }
  printf("%d\n", result);
  return 0;
}