#include #include #include #include #include typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define incII(i, l, r) for(int i = (l) ; i <= (r); i++) #define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--) #define decII(i, l, r) for(int i = (r) ; i >= (l); i--) #define inc( i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec( i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) template void swap(T & x, T & y) { T t = x; x = y; y = t; return; } template T abs(T x) { return (0 <= x ? x : -x); } template T max(T a, T b) { return (b <= a ? a : b); } template T min(T a, T b) { return (a <= b ? a : b); } template bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } } template bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } } template T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- int n, p[4000], a[4000], b[4000]; LL ans; typedef std::pair PII; std::vector vec[3]; bool comp(PII x, PII y) { return (x.first * y.second < y.first * x.second); } double val(PII x) { return static_cast(x.first) / x.second; } int main() { scanf("%d", &n); inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); } inc(i, n) { vec[ p[i] ].push_back(std::make_pair(a[i], a[i] + b[i])); } inc(i, 3) { vec[ i ].push_back(std::make_pair(1, 1)); } inc(i, 3) { std::sort(vec[i].begin(), vec[i].end(), &comp); } /* inc(i, 3) { for(auto && e: vec[i]) { printf("%2d/%2d = %.2f\n", e.first, e.second, static_cast(e.first) / e.second); } printf("\n"); } */ for(auto && e1: vec[1]) { for(auto && e2: vec[2]) { // printf("e1: <%2d,%4d>, e2: <%2d,%4d>, ", e1.first, e1.second, e2.first, e2.second); PII x, y, z; x = std::make_pair(e1.second - e1.first, e1.second); y = std::make_pair(e2.second - e2.first, e2.second); z = std::make_pair((e1.second - e1.first) * e2.second + (e2.second - e2.first) * e1.second, e1.second * e2.second); if(comp(std::make_pair(1, 1), z)) { continue; } if(comp(y, x)) { swap(x, y); } auto lby = std::lower_bound(vec[0].begin(), vec[0].end(), y, &comp); auto lbz = std::lower_bound(vec[0].begin(), vec[0].end(), z, &comp); int v = vec[0].end() - lby, w = (lbz != vec[0].end() && ! comp(*lbz, z) && ! comp(z, *lbz)); ans += v - w; /* // printf("x: <%2d,%2d>, y: <%2d,%2d>, z: <%2d,%2d>, ", x.first, x.second, y.first, y.second, z.first, z.second ); printf("x: [%.2f], y: [%.2f], z: [%.2f], ", val(x), val(y), val(z) ); printf("ans += %d - %d [%]\n", v, w); */ } } printf("%lld\n", ans); return 0; }