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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pii = pair<int,int>;
using Vi = vector<int>;
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define rep(i,b,e) for (int i = (b); i < (e); i++)
#define each(a,x) for (auto& a : (x))
#define all(x) (x).begin(),(x).end()
#define sz(x) int((x).size())
#define endl '\n'


void solve() {
    int n;
    cin >> n;
    map<int, int> M[2];
    for (int i = 0; i < n; i++) {
        int r, w, t;
        cin >> r >> w >> t;
        M[r-1][w-t]++;
    }
    int res = 0;
    for (Pii p : M[0]) {
        res += min(M[0][p.x], M[1][p.x]);
    }
    cout << res << endl;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(10);
    int t = 1; 
    //cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
}