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

using namespace std;

map<int, int> rowsStart;
map<int, int> columnsStart;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int r, w, t;
        cin >> r >> w >> t;

        if (r == 1) {
            if (rowsStart.find(w - t) == rowsStart.end()) {
                rowsStart[w - t] = 1;
            } else {
                rowsStart[w - t] += 1;
            }
        } else {
            if (columnsStart.find(w - t) == columnsStart.end()) {
                columnsStart[w - t] = 1;
            } else {
                columnsStart[w - t] += 1;
            }
        }
    }

    int result = 0;
    for (auto const& x : rowsStart) {
        if (columnsStart.find(x.first) != columnsStart.end()) {
            result += min(columnsStart[x.first], x.second);
        }
    }
    cout << result;
    return 0;
}