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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, r, w, t;
    int ans=0;
    vector<int> a;
    vector<int> b;
    cin >> n;
    while(n--) {
        cin >> r;
        cin >> w >> t;
        switch(r) {
        case 1:
            a.push_back(w-t);
            break;
        case 2:
            b.push_back(w-t);
            break;
        }
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int i=0;
    int j=0;
    while(1) {
        if(i>=a.size() || j>=b.size()) break;
        if(a[i]==b[j]) {
            int i2=i;
            int j2=j;
            while(a[i2]==a[i] && b[j2]==a[i] && i2<a.size() && j2<b.size()) {
                i2++;
                j2++;
            }
            ans+=i2-i;
            i+=i2-i;
            j+=j2-j;
        } else if(b[j]<a[i]) {
            j++;
        } else {
            i++;
        }
    }
    cout << ans;
    return 0;
}