#include #include #include #include #include using namespace std; using int64 = int64_t; int64 gcd(int64 x, int64 y) { if (y == 0) { return x; } return gcd(y, x%y); } struct line { int p; int64 a, b; line() {} bool operator < (const line& o) const { return p < o.p; } }; struct rat { int64 nume, deno; rat(){} rat(int64 a, int64 b): nume(a), deno(b) { int64 t = gcd(nume, deno); nume /= t; deno /= t; } bool operator < (const rat& o) const { return nume * o.deno < deno * o.nume; } }; int N; line l[4040]; int main() { cin >> N; for (int j = 0; j < N; ++j) { cin >> l[j].p >> l[j].a >> l[j].b; } sort(l, l+N); vector ts; map tmp; map crs; int ind0, ind1; for (ind0 = 0; ind0 < N && l[ind0].p == 0; ++ind0) { ts.emplace_back(l[ind0].b, l[ind0].a + l[ind0].b); } for (ind1 = ind0; ind1 < N && l[ind1].p == 1; ++ind1) { ts.emplace_back(l[ind1].b, l[ind1].a + l[ind1].b); } int64 count = 1 + ind1; ts.emplace_back(0, 1); for (int j = 0; j < ind0; ++j) { for (int k = ind0; k < ind1; ++k) { int64 nume = l[j].a * (l[k].a + l[k].b) + l[k].a * (l[j].a + l[j].b); int64 deno = (l[j].a + l[j].b) * (l[k].a + l[k].b); if (nume < deno) { continue; } int64 x = nume - deno; int64 y = 2 * deno - nume; rat hi = rat(y, x+y); if (nume > deno) { ++count; ts.emplace_back(y, x+y); } rat r0(l[j].b, l[j].a+l[j].b); rat r1(l[k].b, l[k].a+l[k].b); rat lo = r0 < r1 ? r1 : r0; if (tmp.find(lo) == end(tmp)) { tmp[lo] = 1; } else { ++tmp[lo]; } if (tmp.find(hi) == end(tmp)) { tmp[hi] = -1; } else { --tmp[hi]; } } } sort(begin(ts), end(ts)); int64 acc = 0; for (pair p : tmp) { acc += p.second; crs[p.first] = acc; } crs[rat(2, 1)] = acc; for (int j = ind1; j < N; ++j) { auto val = rat(l[j].a, l[j].b+l[j].a); { auto it = lower_bound(begin(ts), end(ts), val); count += it - begin(ts); } { auto it = crs.lower_bound(val); count += it->second; } } cout << count << endl; return 0; }