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

using namespace std;

int main() {
    std::map<int, int> maps[2];

    int n;
    scanf("%d", &n);
    while(n--) {
        int type, pos, time;
        scanf("%d %d %d", &type, &pos, &time);

        std::map<int, int> &ref = maps[type-1];

        if (ref.find(pos-time) == ref.end()) {
            ref[pos-time] = 1;
        } else {
            ref[pos - time]++;
        }
    }

    unsigned long long count = 0;

    for (auto now: maps[0]) {
        if (maps[1].find(now.first) != maps[1].end()) {
            auto in_this = now.second;
            auto in_second = maps[1][now.first];

            count += std::min(in_this, in_second);
        }
    }
    cout << count << endl;
    return 0;
}