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
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXW = 1000*1000 + 7;

int ile[2*MAXW][2];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	set<int> ind;
	for(int i = 1; i <= n; i++)
	{
		int r, w, t;
		cin >> r >> w >> t;
		if(r == 1)
		{
			ile[MAXW + w-t][0]++;
			ind.insert(MAXW + w-t);
		}
		else
			ile[MAXW + w-t][1]++;
	}
	int wyn = 0;
	for(auto& i : ind)
		wyn += min(ile[i][0], ile[i][1]);
	cout << wyn << '\n';
	return 0;
}