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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second

#define sz(x) (x).size()
#define all(x) (x).begin(), (x).end()

using ll = long long;
using pi = pair<int, int>;
using pll = pair<ll, ll>;

using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vpi = vector<pi>;
using vpll = vector<pll>;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    int n;
    cin >> n;
    vpi v;
    int a, b, c;
    for (int i = 1; i <= n; i++)
    {
        cin >> a >> b >> c;
        a--;
        v.pb({abs(b - c), a});
    }
    sort(all(v));
    //for (auto i : v)
        //cout << i.f << ": " << i.s << endl;
    int tmp1 = 0;
    int tmp0 = 0;
    int wyn = 0;
    if (v[0].s)
        tmp1++;
    else
    {
        tmp0++;
    }

    for (int i = 0; i < sz(v); i++)
    {

        if (i == sz(v) - 1 || v[i].f != v[i + 1].f)
        {
            if (tmp1 != 0 && tmp0 != 0)
                wyn += min(tmp1, tmp0);
            tmp1 = 0;
            tmp0 = 0;
            if (v[i].s)
                tmp1++;
            else
                tmp0++;
        }
        else
        {
            if (v[i + 1].s)
                tmp1++;
            else
                tmp0++;
        }
    }
    cout << wyn;
}