#include #include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) typedef long long ll; using namespace std; const long double eps = 1e-18; int main() { int n; cin >> n; array, 3> qs = {}; repeat (i,n) { int p, a, b; cin >> p >> a >> b; qs[p].push_back(a /(long double) (a + b)); } repeat (i,3) { qs[i].push_back(1); whole(sort, qs[i]); } ll cnt = 0; repeat (i,3) { for (long double q1 : qs[(i + 1) % 3]) { for (long double q2 : qs[(i + 2) % 3]) { long double qm = max(1 - q1, 1 - q2); long double qc = (1 - q1) + (1 - q2); if (qc <= 1) { int lm = whole(lower_bound, qs[i], qm - eps) - qs[i].begin(); int lc = whole(lower_bound, qs[i], qc - eps) - qs[i].begin(); cnt += qs[i].size() - lm - (abs(qs[i][lc] - qc) < eps); } } } } cout << cnt / 3 << endl; return 0; }