#include #include #include #include typedef long long signed int LL; #define incID(i, l, r) for(int i = (l) ; i < (r); i++) #define inc( i, n) incID(i, 0, n) struct Frac { LL p, q; Frac(LL pp, LL qq) { p = pp; q = qq; } bool operator<(const Frac & obj) const { return (this -> p) * (obj.q) < (obj.p) * (this -> q); } bool operator==(const Frac & obj) const { return (this -> p) * (obj.q) == (obj.p) * (this -> q); } double val() { return static_cast(p) / q; } }; int n, p[4000], a[4000], b[4000]; LL ans; std::vector vec[3]; 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(Frac(a[i], a[i] + b[i])); } inc(i, 3) { vec[ i ].push_back(Frac(1,1)); } inc(i, 3) { std::sort(vec[i].begin(), vec[i].end()); } for(auto && e1: vec[1]) { for(auto && e2: vec[2]) { Frac x(e1.q - e1.p, e1.q); Frac y(e2.q - e2.p, e2.q); Frac z((e1.q - e1.p) * e2.q + (e2.q - e2.p) * e1.q, e1.q * e2.q); if(Frac(1, 1) < z) { continue; } if(y < x) { std::swap(x, y); } auto lby = std::lower_bound(vec[0].begin(), vec[0].end(), y); auto lbz = std::lower_bound(vec[0].begin(), vec[0].end(), z); int v = vec[0].end() - lby, w = (lbz != vec[0].end() && *(lbz) == z); ans += v - w; } } printf("%lld\n", ans); return 0; }