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

const int N = 2e6 + 55;
const int Z = 1e6;

int n;
pair<int, int> tab[N];
vector<int> gdzie;

int main()
{
	int res = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int r, w, t;
		scanf("%d%d%d", &r, &w, &t);
		if (r == 1) {
			tab[Z + w - t].first++;
		}
		else {
			tab[Z + w - t].second++;
		}
		gdzie.push_back(Z + w - t);
	}
	for (int i : gdzie) {
		res += min(tab[i].first, tab[i].second);
		tab[i].first = tab[i].second = 0;
	}
	printf("%d\n", res);
}