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

using namespace std;

int n;
vector<int> vert, hor;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b, c; cin >> a >> b >> c;
		(a == 1 ? vert : hor).push_back(b - c);
	}
	sort(vert.begin(), vert.end());
	sort(hor.begin(), hor.end());

	unsigned i = 0, j = 0;
       	int odp = 0;
	while (i < vert.size() && j < hor.size())
	{
		if (vert[i] < hor[j])
			++i;
		else if (vert[i] > hor[j])
			++j;
		else
		{
			int sum = hor[j], num_of_vert = 0, num_of_hor = 0;
			while (i < vert.size() && vert[i] == sum)
				++num_of_vert, ++i;
			while (j < hor.size() && hor[j] == sum)
				++num_of_hor, ++j;
			odp += min(num_of_vert, num_of_hor);
		}
	}
	cout << odp << '\n';
}