#include #define REP_(i, a_, b_, a, b, ...) \ for (int i = (a), END_##i = (b); i < END_##i; ++i) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) using i64 = long long; void print() { std::cout << "\n"; } template void print(const T &x) { std::cout << x << "\n"; } template void print(const Head &head, Tail... tail) { std::cout << head << " "; print(tail...); } struct Input { template operator T() const { T x; std::cin >> x; return x; } } in; #ifdef MY_DEBUG #include "debug_dump.hpp" #else #define DUMP(...) #endif using namespace std; int m0[400020]; int m1[400020]; const int kOffset = 200010; auto solve() { const int n = in; int mx = 0, mn = 2 * kOffset; REP(i, n) { const int a = in, b = in, t = in; int x = b - t + kOffset; if (a == 0) { ++m0[x]; } else { ++m1[x]; } mx = max(mx, x); mn = min(mn, x); } i64 ans = 0; for (int i = mn; i <= mx; ++i) { ans += i64(m0[i]) * m1[i]; } return ans; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); print(solve()); }