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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define lll __int128
#define ull unsigned long long
#define fi first
#define se second
#define db double
#define ld long double
#define lld __float128

/// order_of_key, find_by_order

template<class T, class COMP>
using custom_set = tree<T, null_type, COMP, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd_64(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    pair<pair<int, int>, int> dat[n];
    for(int i = 0; i < n; i++)
    {
        cin >> dat[i].fi.fi >> dat[i].fi.se >> dat[i].se;
    }
    pair<int, int> vc[n];
    for(int i = 0; i < n; i++)
    {
        if(dat[i].fi.fi == 1)
        {
            int vl = dat[i].fi.se - dat[i].se;
            vc[i] = {vl, 1};
        }
        else
        {
            int vl = dat[i].fi.se - dat[i].se;
            vc[i] = {vl, 2};
        }
    }
    sort(vc, vc + n);
    int ans = 0;
    int c0 = 0, c1 = 0, cur = -1e9;
    for(int i = 0; i < n; i++)
    {
        if(vc[i].fi != cur)
        {
            ans += min(c0, c1);
            c1 = 0; c0 = 0;
            cur = vc[i].fi;
        }
        if(vc[i].se == 1)
            c0++;
        else
            c1++;
    }
    ans += min(c0, c1);
    cout << ans;

}






































/// shche ne vmerla Ykraina