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

using namespace std;
 
int main()
{
    int n;
    int t, x, y;
    map<int, int> m1, m2;

    scanf("%d",&n);
    for (int i=0; i<n; i++)
    {
        scanf("%d%d%d",&t,&x,&y);
        if (t == 1)
            if (m1.find(x-y) == m1.end())
                m1[x-y] = 1;
            else
                m1[x-y]++;
        else
            if (m2.find(x-y) == m2.end())
                m2[x-y] = 1;
            else
                m2[x-y]++;
    }

    map<int, int>::iterator it;

    int result = 0;
    for ( it = m1.begin(); it != m1.end(); it++ )
    {
        if (m2.find(it->first) != m2.end())
        {
            result += min(it->second, m2[it->first]);
        }
    }

    printf("%d\n",result);

}