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
#include <iostream>
#include <fstream>
#include <map>
#include <array>

using namespace std;

#ifdef USE_CERR_LOG
#define LOG if (true) cerr
const bool LogEnabled = true;
#else
#define LOG if (false) cerr
const bool LogEnabled = false;
#endif

bool LogBigEnabled = true;

#ifdef USE_FILE_CIN
ifstream fin("sam0.in");
#define cin fin
#endif

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;



int main() {
    int n;
    int typ, depot, tim;
    map<int, array<int, 2>> diffs; 
    
    cin >> n;
    
    while (n--) {
        cin >> typ >> depot >> tim;
        int diff = depot - tim;
        
        if (diffs.count(diff) == 0) {
            diffs[diff] = {0, 0};
        }
        
        diffs[diff][typ - 1] ++;
    }
    
    int result = 0;
    for (auto& entry : diffs) {
        result += min(entry.second[0], entry.second[1]);
    }
    
    cout << result;
    
    return 0;
}