/** * @FileName a.cpp * @Author kanpurin * @Created 2021.09.11 18:29:30 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int n;cin >> n; unordered_map mp; vector a(n),b(n),t(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i] >> t[i]; if (a[i] == 0) mp[b[i]-t[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) ans += mp[b[i]-t[i]]; } cout << ans << endl; return 0; }