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

using namespace std;
const int N = 500 * 10000 + 7;
map<int, int> ile1, ile2;
int tab[N];

void Samochody()
{
	int n, r, s, t, i, w;
	cin >> n;
	w = 0;
	for(i = 1; i <= n; ++i)
	{
		cin >> r >> s >> t;
		tab[i] = s - t;
		if(r == 1)
			++ile1[s - t];
		else
			++ile2[s - t];
	}
	for(i = 1; i <= n; ++i)
	{
		if(ile1.find(tab[i]) == ile1.end())
			ile1[tab[i]] = 0;
		if(ile2.find(tab[i]) == ile2.end())
			ile2[tab[i]] = 0;
		w += min(ile1[tab[i]], ile2[tab[i]]);
		if(ile1[tab[i]] == min(ile1[tab[i]], ile2[tab[i]]))
			ile1[tab[i]] = 0;
		else
			ile2[tab[i]] = 0;
	}
	
	cout << w << "\n";
}

int main ()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Samochody();
	
	
	return 0;
}