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
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main() {

	int n_max = 1000001;
	int n;
    scanf("%d", &n);
	// int dist [n_max];

    int * to_east = new int[n_max];
    int * to_north = new int[n_max];
	// int to_north [n_max];

    int * to_east_min = new int[n_max];
    int * to_north_min = new int[n_max];
	// int to_east_min [n_max];
	// int to_north_min [n_max];

	int t, w, type, dist;
	int max_dist = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d", &type);
		scanf("%d", &w);
		scanf("%d", &t);
		dist = w - t;
		if (dist >= 0) {
			if (type == 1) {
				to_north[dist] += 1;
				// cout << "to north" << dist << endl;
			} else {
				to_east[dist] += 1;
				// cout << "to east" << dist << endl;
			}
			max_dist = max(dist, max_dist);	
		} else {
			dist *= -1;
			if (type == 1) {
				to_north_min[dist] += 1;
				// cout << "to north -- " << dist << endl;
			} else {
				to_east_min[dist] += 1;
				// cout << "to east -- " << dist << endl;
			}
			max_dist = max(dist, max_dist);
		}
		
	}
	// cout << max_dist << endl;
	int res = 0;
	int to_remove = 0;
	for (int i = 0; i < n_max; i++) {
		if ((to_east[i] > 0) && (to_north[i] > 0)) {
			to_remove = min(to_east[i], to_north[i]);
			// cout << to_east[i] << " " << to_north[i] << endl;
			res += to_remove;
		}
		if ((to_east_min[i] > 0) && (to_north_min[i] > 0)) {
			to_remove = min(to_east_min[i], to_north_min[i]);
			// cout << to_east_min[i] << " " << to_north_min[i] << endl;
			res += to_remove;
		}
	}
	printf("%d\n", res);
    return 0;
}