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
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

const int maxn = 500123;
const int maxd = 1000005;

int diffs[2][2 * maxd];

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int r, w, t;
		cin >> r >> w >> t;
		r--;
		int d = w - t + maxd;
		diffs[r][d]++;
	}

	int res = 0;
	for (int i = 0; i < 2 * maxd; i++) {
		if (diffs[0][i] > 0 && diffs[1][i] > 0)
			res += min(diffs[0][i], diffs[1][i]);
	}

	cout << res << "\n";
	
	return 0;	
}