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
#include <cstdio>
using namespace std;

// values too big just in case
const int offset = 1500000;
const int maxline = 4000000;
int lines[4][maxline];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		int r, w, t;
		scanf("%d %d %d", &r, &w, &t);
		lines[r][w-t+offset]++;
	}
	int wynik = 0;
	for (int i = 0; i < maxline; ++i){
		if (lines[1][i] > lines[2][i]) {
			wynik += lines[2][i];
		} else {
			wynik += lines[1][i];
		}
	}
	printf("%d\n", wynik);
	return 0;
}