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
49
#include <iostream>

using namespace std;

int main(){

    int size = 1000000;

    int* H = new int[2*size + 1];
    int* V = new int[2*size + 1];

    int n;

    for(int i=0; i<2*size + 1; i++){
        H[i] = 0;
        V[i] = 0;
    }

    cin>>n;

    for(int i=0; i<n; i++){
        int r, w, t;

        cin>>r>>w>>t;

        if(r==1){
            H[size + w-t]++;
        }
        else{
            V[size + w-t]++;
        }
    }

    int counter = 0;

    for(int i=0; i<2*size + 1; i++){
        if(H[i] < V[i]){
            counter += H[i];
        }
        else{
            counter += V[i];
        }
    }

    cout<<counter;


    return 0;
}