//#define _GLIBCXX_DEBUG #include #include #include #include using namespace std; using namespace atcoder; using mint = modint1000000007; using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vb = vector; using vvb = vector; using vm = vector; using vvm = vector; using vpi = vector; using vvpi = vector; using vpl = vector; using vvpl = vector; const int inf = 1 << 30; const ll INF = 1LL << 60; #define rep(i,m,n) for (int i = m; i < (int)(n); i++) #define rrep(i,m,n) for (int i = m; i > (int)(n); i--) int main(){ int n; cin >> n; vi A(4e5+10),B(4e5+10); rep(i,0,n){ int a,b,t; cin >> a >> b >> t; if (a == 1){ A[t-b+2e5]++; } if (a == 0){ B[t-b+2e5]++; } } ll ans = 0; rep(i,0,4e5+10){ ans += A[i]*B[i]; } cout << ans << endl; }