#include #include #include #include #include #include #include #include using namespace std; int main(){ int n; cin >> n; int ans = 0; mapred; vectorblue; for(int i = 0; i < n; i++){ int a,b,t; cin >> a >> b >> t; if(a==0){ if (red.count(b - t))red[b - t]++; else red[b - t] = 1; }else{ blue.push_back(b-t); } } for(auto x: blue){ if(red.count(x)){ ans += red[x]; } } cout << ans << endl; return 0; }