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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<bits/stdc++.h>
#define mk make_pair
#define ff first
#define sc second
typedef unsigned int uint;

using namespace std;

vector<pair<int,int> > v1,v2;
int n,wyn;

long long il (pair<int,int> p1,pair<int,int> p2)
{
	return p1.ff+p1.sc-p2.ff-p2.sc;
}

bool cmp(pair<int,int> p1,pair<int,int> p2) 
{
	return il(p1,p2)<0;
}

int main()
{
	scanf("%d", &n);
	for(int i = 0;i<n;++i)
	{
		int a,b,c;
		scanf("%d%d%d", &a, &b, &c);
		if(a == 1)
		{
			v1.push_back(mk(-c,b));
		}
		else
		{
			v2.push_back(mk(b,-c));
		}
	}
	sort(v1.begin(),v1.end(),cmp);
	sort(v2.begin(),v2.end(),cmp);
	uint i = 0;
	uint j = 0;
	while((i<v1.size())&&(j<v2.size()))
	{
		if(il(v1[i],v2[j])==0)
		{
			int s1 = 1;
			int s2 = 1;
			while((i<v1.size()-1)&&(il(v1[i],v1[i+1])==0))
			{
				++i;
				++s1;
			}
			while((j<v2.size()-1)&&(il(v2[j],v2[j+1])==0))
			{
				++j;
				++s2;
			}
			wyn += min(s1,s2);
			++i;
			++j;
		}
		else
		{
			if(il(v1[i],v2[j])<0)	
			{
				++i;
			}
			else
			{
				++j;
			}
		}
	}
	printf("%d\n", wyn);
}