#include #include #include #include using namespace std; int main() { vector> L(3, vector(1, 0.0)); int N; cin >> N; for (int i = 0; i < N; ++i) { int p; long double a, b; cin >> p >> a >> b; L[p].push_back(b / (a + b)); } sort(L[0].begin(), L[0].end()); sort(L[1].begin(), L[1].end()); sort(L[2].begin(), L[2].end()); int ANS = 0; set SET(L[2].begin(), L[2].end()); for (long double x : L[0]) { for (long double y : L[1]) { if (x + y > 1.0) { break; } long double MAX = max(x, y); auto it = lower_bound(L[2].begin(), L[2].end(), 1.0 - MAX); int k = distance(L[2].begin(), it); ANS += k; long double z = x + y; if (z < 1.0 - MAX && SET.find(1.0 - z) != SET.end()) { ANS -= 1; } } } cout << ANS << endl; return 0; }