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
#include<bits/stdc++.h>
using namespace std;

vector<int> v1,v2;

int main()
{
    int n, a, b, c;
    scanf("%d", &n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d", &a, &b, &c);
        if(a == 1) v1.push_back(b-c);
        else v2.push_back(b-c);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    a = b = c = 0;
    while(b < v1.size() && c < v2.size())
    {
        if(v1[b] < v2[c]) b++;
        else if(v2[c] < v1[b]) c++;
        else
        {
            while(b < v1.size() && c < v2.size() && v1[b] == v2[c])
            {
                b++;
                c++;
                a++;
            }
        }
    }
    printf("%d", a);
    return 0;
}