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
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <algorithm>

using namespace std;

pair<int, int> d[500001];

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);
    d[i] = {w - t, r};
  }

  sort(d, d + n);
  

  int i = 0;
  int ret = 0;
  while (i < n)
  {
    int pop = d[i].first;
    int r1 = 0, r2 = 0;
    
    while (i < n && pop == d[i].first)
    {
      if (d[i].second == 1)
      {
        r1++;
      }
      else
      {
        r2++;
      }
      i++;
    }
    ret += min(r1, r2);    
  }
  
  printf("%d", ret);
  
  return 0;
}