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
47
48
49
50
51
52
53
#define _CRT_SECURE_NO_WARNINGS 1
#define _WINSOCK_DEPRECATED_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

long long t1[2200200];
long long t2[2200200];

int main()
{
	int n;

	scanf("%d", &n);


	for (int i = 0; i < n; ++i)
	{
		long long r, w, t;
		scanf("%lld%lld%lld", &r, &w, &t);
		
		long long nt = t - (w - 1) + 1100100;

		if (r == 1)
		{
			t1[nt]++;
		}
		else
		{
			t2[nt]++;
		}
	}

	//sort(d1.begin(), d1.end());
	//sort(d2.begin(), d2.end());

	long long result = 0;
	for (int i = 0; i < 2200200; ++i)
	{
		if (t1[i] > 0 && t2[i] > 0)
		{
			result += min(t1[i], t2[i]);
		}
	}

	printf("%lld", result);
}