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
#include <iostream>
#include <map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    long r, w, t;
    map<long, long> firstType;
    map<long, long> secondType;
    for (int i = 0; i < n; i++)
    {
        cin >> r >> w >> t;
        long s = w - t;
        if (r == 1)
        {
            map<long, long>::iterator tmp = firstType.find(s);
            if (tmp == firstType.end())
            {
                firstType.insert(pair<long, long>(s, 1));
            }
            else
            {
                firstType.insert(pair<long, long>(s, tmp->second + 1));
            }
        }
        else
        {
            map<long, long>::iterator tmp = secondType.find(s);
            if (tmp == secondType.end())
            {
                secondType.insert(pair<long, long>(s, 1));
            }
            else
            {
                secondType.insert(pair<long, long>(s, tmp->second + 1));
            }
        }
    }

    long result = 0;
    map<long, long>::iterator it = firstType.begin();
    while (it != firstType.end())
    {
        long key = it->first;
        map<long, long>::iterator otherIt = secondType.find(key);
        if (otherIt != secondType.end())
        {
            result += min(it->second, otherIt->second);
        }
        it++;
    }
    cout << result << endl;
    return 0;
}