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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <bits/stdc++.h>


#define ll long long
using namespace std;

int n;
vector<pair<int,int>> ones;
vector<pair<int,int>> twos;
vector<int> co;
vector<int> ct;


pair<int,int> findMax(){
	ll indi, indj;
	int  maxi = 0;
//	cout << "b" << endl;
//	cout << co.size() << " " << ct.size() << endl;
	for(int i = 0;i<co.size();i++){
		if(co[i]>maxi){
			maxi = co[i];
			indi = (ll)i;
		}
		
	}
//	cout << "b" << endl;
	maxi = 0;
	for(int i = 0;i<ct.size();i++){
		if(ct[i]> maxi){
			maxi = ct[i];
			indj = (ll)i;
		}
		
	}
//	cout << "b" << endl;
//	cout<<indi << " " << indj << endl;
	if(co[indi]>ct[indj]){
//cout << "c" << endl;
		 return make_pair(indi, 1);
	 }
	else return make_pair(indj, 2);

}


int main(){
	
	scanf("%d", &n);
	for(int i = 0;i<n; i++){
		int r, p, t;
		scanf("%d %d %d", &r, &p, &t);
//		cout<<r <<" " << p<<" "<< t<< endl;
		if(r == 1)
				ones.push_back(make_pair(p,t));
		else
				twos.push_back(make_pair(p,t));
	}
	vector<vector<bool>> crossings(ones.size(),vector<bool>(twos.size(), false));

	co.resize(ones.size(),0);
	ct.resize(twos.size(),0);
	bool falsy = false;
	for(int i = 0;i<ones.size();i++){
		for(int j = 0; j <twos.size();j++){
//			cout<<"PIERWSZE" <<ones[i].first << " " << twos[j].second<< "_= "<< ones[i].first + twos[j].second <<endl;
	//		cout<<"DRUGIE "<< ones[i].second << " "<<twos[j].first<< " = " << ones[i].second + twos[j].first<< endl;
			if(ones[i].first + twos[j].second == ones[i].second + twos[j].first){
				falsy = true;
				crossings[i][j] = true;
				co[i] += 1;
				ct[j] += 1;
			}
		}
	}
	if(falsy == false){
		 printf("0");
		 return 0;
	}
//for(auto& i : co){
//		cout << i << endl;
//	}
//	cout << " ";
//	for(auto& j : ct){
//		cout << j << " ";
//	}
//cout << endl;
//	cout << "a" << endl;
int z = 1;
while(true){
	
//	cout << "a" << endl;
	pair<int,int> tmp =findMax();
//	cout << tmp.first << " - "<< tmp.second << endl;
//	cout << "a" << endl;
	if(tmp.second == 1){
		for(int k = 0; k<crossings[0].size(); k++){
	//		if(crossings[tmp.first][k]==true){
				crossings[tmp.first][k] = false;
//			}
		}
	}
	else if(tmp.second == 2){
		for(int k = 0; k<crossings.size(); k++){
//			if(crossings[k][tmp.first]==true){
				crossings[k][tmp.first] = false;
//			}
		}
	}
//	cout << "a" << endl;
	co.clear();
	ct.clear();
	co.resize(crossings.size(),0);
	ct.resize(crossings[0].size(),0);
	bool ch = false;

	for(int i = 0;i<crossings.size();i++){

		for(int j = 0; j <crossings[0].size();j++){

			if(crossings[i][j] == true){

				ch = true;
				ct[j] += 1;
				co[i] += 1;
			}
		}
	}
	/*
	for(auto& i : co){
		cout << i << endl;
	}
	cout << " ";
	for(auto& j : ct){
		cout << j << " ";
	}
	cout << endl;
	*/
	
	if(ch == false){
		printf("%d", z);
		return z;
	}
	z++;
	
}
	
}