#include using namespace std; #define rep(i,a,b) for(int i=a;i vec[3]; ld EPS = 1e-18; //----------------------------------------------------------------------------------- ll count() { ll ans = 0; sort(vec[2].begin(), vec[2].end()); for (ld a : vec[0]) for (ld b : vec[1]) { // Naive /*for (ld c : vec[2]) { ld sum = a + b + c; if (abs(1 - sum) < EPS) continue; ld ab = a + b; ld bc = b + c; ld ac = a + c; if (ab <= 1 && bc <= 1 && ac <= 1) ans++; }*/ // Optimized ld ab = a + b; if (1 < ab) continue; int minus = 0; // c = 1 - a - b があるか探す int lo = lower_bound(vec[2].begin(), vec[2].end(), 1 - a - b - EPS) - vec[2].begin(); int up = upper_bound(vec[2].begin(), vec[2].end(), 1 - a - b + EPS) - vec[2].begin(); if (lo != up) minus = -1; // c <= min(1-b,1-a) の個数を探す up = upper_bound(vec[2].begin(), vec[2].end(), min(1 - b, 1 - a) + EPS) - vec[2].begin(); ans += up + minus; } return ans; } //----------------------------------------------------------------------------------- int main() { cin >> N; rep(i, 0, 3) vec[i].push_back(0); rep(i, 0, N) { int P, A, B; scanf("%d%d%d", &P, &A, &B); vec[P].push_back((ld)B / (ld)(A + B)); } cout << count() << endl; }