typedef long long ll; typedef long double ld; #include using namespace std; #define int long long signed main(){ ll n; std::cin >> n; map r,b; for (int i = 0; i < n; i++) { ll a,bb,t; std::cin >> a>>bb>>t; if(a==0){ r[bb-t]++; }else{ b[bb-t]++; } } ll ans = 0; for (auto e : b) { ans += r[e.first]*e.second; } std::cout << ans << std::endl; }