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
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<cstdlib>

using namespace std;

#define PII          pair< int, int >
#define PLI          pair< long long, int >
#define VPII         vector< PII >
#define VPLI         vector< PLI >
#define MP           make_pair
#define REP(i,n)     for(int i=0;i<(n);++i)
#define FOR(i,a,b)   for (int i=(a); i<(b); ++i)
#define FORD(i,a,b)  for (int i=(a)-1; i>=(b); --i)
#define EACH(a, x)   for (auto& a : (x))
#define ALL(x)       (x).begin(), (x).end()

#define INF INT_MAX
#define MAXT 1000000

int n;
vector<int> types;
int by_type[2][2 * MAXT + 1];
int r, w, t, type;

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    REP(i, n) {
        cin >> r >> w >> t;
        type = MAXT + w - t;
        types.push_back(type);
        by_type[r - 1][type]++;
    }
    int res = 0;
    EACH(elem, types) {
        res += min(by_type[0][elem], by_type[1][elem]);
        by_type[0][elem] = by_type[1][elem] = 0;
    }
    cout << res << endl;
}