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
#include <iostream>
#define OFFSET 1000000

using namespace std;

struct ln{
    int a = 0, b = 0;
} tab[2000001];

int main (){
    ios_base::sync_with_stdio(0);

    int t, a, b, i, n;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> t >> a >> b;
        if(t == 1)
            tab[a-b+OFFSET].a++;
        else
            tab[a-b+OFFSET].b++;
    }

    t = 0;
    for(i = 0; i < 2000001; i++){
        t += min(tab[i].a, tab[i].b);
    }

    cout << t;

    return 0;
}