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

using namespace std;

int bylop [1000010][2];
int bylom [1000010][2];

int main()
{
    int il, typ, a, b, suma = 0;
    cin >> il;
    for (int q = 0; q < il; q++){
        cin >> typ >> a >> b;
        if (a-b >= 0){
            bylop [a-b][typ-1]++;
        }
        else bylom [(a-b)*-1][typ-1]++;
    }
    //cout << "------bylop--------\n";
    for (int q = 0; q < 1000008; q++){
        suma += min(bylop[q][0], bylop[q][1]);
        //cout << q << "| " << bylop[q][0] << " " << bylop[q][1] << " |" << suma << '\n';
    }
    //cout << "---------bylom-------\n";
    for (int q = 0; q < 1000008; q++){
        suma += min(bylom[q][0], bylom[q][1]);
        //cout << q << "| " << bylom[q][0] << " " << bylom[q][1] << " |" << suma << '\n';
    }
    cout << suma;
}