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
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	multiset<int> dost1;
	multiset<int> dost2;
	int r,w,t;
	for (int i=0;i<n;++i)
	{
		cin >> r >> w >> t;
		if (r==1)
			dost1.insert(t-w);
		else dost2.insert(t-w);
	}
	vector<int> kolizje;
	set_intersection(dost1.begin(),dost1.end(),dost2.begin(),dost2.end(),back_inserter(kolizje));
	cout << kolizje.size() << endl;
	return 0;
}