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
#include <iostream>
   
    #include <stdio.h>
   
    using namespace std;
   
  
  int smaller(int a, int b) {
    return a < b ? a : b;
  }

  int main() {
    int n;
    cin >> n;

    int histogram[2][2000009];
    for (int type = 0; type < 2; type++) {
      for (int street = 0; street < 2000009; street++) {
        histogram[type][street] = 0;
      }
    }

    for (int i = 0; i < n; i++) {
      int type;
      cin >> type;
      int street;
      cin >> street;
      int time;
      cin >> time;

      histogram[type - 1][street - time + 1000000]++;
    }

    int count = 0;
    for (int i = 0; i < 2000009; i++) {
      count += smaller(histogram[0][i], histogram[1][i]);
    }

    printf("%d", count);
    return 0;
  }