#include using namespace std; int n, a, b, t, w = -200000; long long c = 0, d = 0, m = 0; vector> v; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b >> t; v.push_back({ b - t, a }); } sort(v.begin(), v.end()); for (auto u : v) { if (w != u.first){ m += c * d; w = u.first; c = 0; d = 0; } if (u.second) c++; else d++; } m += c * d; cout << m << endl; }