#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll ans = 0; int mx = 200000, n; cin >> n; vector> cnt(2 * mx + 1); for(int i = 0; i < n; i++){ int c, b, t; cin >> c >> b >> t; ans += cnt[b - t + mx][c ^ 1]; cnt[b - t + mx][c]++; } cout << ans << '\n'; }