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
#include "bits/stdc++.h"
using namespace std;

typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)

// Ignacy Boehlke

#define MX 1000001
int arr[2][2 * MX + 1];

int main() {
    int n;
    scanf("%d", &n);

    set<pair<int, pii>> S;
    int r, w, t;
    REP(i, n) {
        scanf("%d%d%d", &r, &w, &t); --r; --w;
        if (S.find({r, {w, t}}) != S.end()) continue;
        S.emplace(r, make_pair(w, t));
        ++arr[r][w - t + MX];
    }
    int keep = 0;
    REP(i, 2 * MX) keep += max(arr[0][i], arr[1][i]);

    printf("%d\n", n - keep);
}