#include using namespace std; #define _p(...) (void)printf(__VA_ARGS__) #define forr(x,arr) for(auto&& x:arr) #define _overload3(_1,_2,_3,name,...) name #define _rep2(i,n) _rep3(i,0,n) #define _rep3(i,a,b) for(int i=int(a);i=int(a);i--) #define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define bit(n) (1LL<<(n)) #define sz(x) ((int)(x).size()) #define fst first #define snd second using ll=long long;using pii=pair; using vb=vector;using vs=vector; using vi=vector;using vvi=vector;using vvvi=vector; using vl=vector;using vvl=vector;using vvvl=vector; using vd=vector;using vvd=vector;using vvvd=vector; using vpii=vector;using vvpii=vector;using vvvpii=vector; templateT read(){T t;cin>>t;return t;} templateostream&operator<<(ostream&o,const pair&p){o<<'('< 0) return 1; if (ret < 0) return -1; return 0; } bool cmp_b(const pii &lhs, decltype(lhs) rhs) { return cmp(lhs.A, lhs.B, rhs.A, rhs.B) <= 0; } void Main() { int n = read(); vector> L; vvpii R(3); rep(i, n) { int t = read(); int a = read(); int b = read(); int g = __gcd(a, b); a /= g; b /= g; R[t].emplace_back(a, b); } rep(i, 3) sort(all(R[i]), cmp_b); //rep(ii,sz(R)) { cout << "R["< int { int ok = sz(S); int ng = -1; auto check = [&](int x) -> bool { int xa = S[x].A; int xb = S[x].B; return cmp(xb, xa + xb, a, a + b) >= 0; }; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; bool c = check(mid); // cout << "ok: " << ok << ", ng: " << ng << ", "; // cout << "check(" << mid << ") -> " << c << endl; if (c) ok = mid; else ng = mid; } return ok; }; forr(ab, R[1]) { int a = ab.A; int b = ab.B; int c0 = bs(a, b, R[0]); //_p("R1: a:%d, b:%d, c0: %d\n", a, b, c0); ans += c0; } vpii X; map CC; { forr(ab, R[0]) { ll a = ab.A; ll b = ab.B; forr(cd, R[0]) { ll c = cd.A; ll d = cd.B; if (a*(c+d) + c*(a+b) >= (a+b)*(c+d)) { int cm = cmp(a, a+b, c, c+d); if (cm <= 0) { X.emplace_back(a, b); } else { X.emplace_back(c, d); } { ll e = d + b; ll f = c - b; if (e != 0 && f != 0) { ll g = __gcd(e, f); e /= g; f /= g; CC[(e << 32) + f]++; //_p("CC[%lld,%lld]++\n", e, f); } } } } } } sort(all(X), cmp_b); //cout << "X:"; rep(ii,sz(X)) cout << ' ' << X[ii]; cout << endl; forr(ab, R[2]) { ll a = ab.A; ll b = ab.B; int c0 = bs(a, b, R[0]); int c1 = bs(a, b, R[1]); //_p("R2: a:%lld, b:%lld, c0: %d, c1: %d\n", a, b, c0, c1); ans += c0; ans += c1; // b/(a+b) より大きな X を数える // X は単調増加 { int ok = sz(X); int ng = -1; auto check = [&](int x) -> bool { return cmp(b, a + b, X[x].A, X[x].A + X[x].B) <= 0; }; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; bool c = check(mid); // cout << "ok: " << ok << ", ng: " << ng << ", "; // cout << "check(" << mid << ") -> " << c << endl; if (c) ok = mid; else ng = mid; } // cout << "ok: "<