#include using namespace std; int main() { int n; long double eps = 1e-17L; cin >> n; vector lines[3]; for (int i = 0; i < 3; i++) { lines[i].emplace_back(0.0); } for (int i = 0; i < n; i++) { int p, a, b; cin >> p >> a >> b; lines[p].emplace_back(b / (long double)(a + b)); } for (int i = 0; i < 3; i++) sort(lines[i].begin(), lines[i].end()); long long ans = 0; for (long double a : lines[0]) { for (long double b : lines[1]) { if (a + b > 1 + eps) continue; int ok = 0, ng = lines[2].size(); while (ok < ng - 1) { int m = (ok + ng) >> 1; long double c = lines[2][m]; if (a + c < 1 + eps && b + c < 1 + eps) ok = m; else ng = m; } ans += ok + 1; int l = 0, r = lines[2].size() - 1; while (1) { int m = (l + r) >> 1; long double c = lines[2][m]; if (abs(a + b + c - 1) < eps) { --ans; break; } if (l >= r) break; if (a + b + c < 1) l = m + 1; else r = m - 1; } } } cout << ans << "\n"; return 0; }