1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000000
int horizontal[2*MAXN+5], vertical[2*MAXN+5], n, r, w, t, res;

int main(){
  scanf("%d", &n);
  for(int i = 0; i<n;i++){
    scanf("%d%d%d", &r, &w, &t);
    if (r == 1){
      vertical[MAXN + w - t]++;
    } else {
      horizontal[MAXN + w - t]++;
    }
  }
  for(int i = 0; i <= 2*MAXN; i++){
    res += min(horizontal[i], vertical[i]);
  }
  printf("%d\n", res);
}