#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; typedef pair pll; bool les(pll x, pll y) { return x.first*y.second < y.first*x.second; } bool f(pll x, pll y) { return x.first*y.second + x.second*y.first <= x.second*y.second; } bool g(pll x, pll y) { return x.first*y.second + x.second*y.first < x.second*y.second; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vi p(N), a(N), b(N); rep(i, N)cin >> p[i] >> a[i] >> b[i]; vector> vv(3); rep(i, N) { vv[p[i]].push_back(mp(b[i], a[i] + b[i])); } rep(i, 3)sort(all(vv[i]), les); ll ans = N + 1; if(sz(vv[0])*sz(vv[1])*sz(vv[2])) each(s, vv[0]) { each(t, vv[1]) if(f(s, t) && f(s,vv[2][0]) && f(t, vv[2][0])){ int lb = 0, ub = sz(vv[2]), m; while(ub - lb > 1) { m = (lb + ub) >> 1; ((f(s, vv[2][m]) && f(t, vv[2][m])) ? lb : ub) = m; } ll d = s.second*t.second; pll ng(d - s.first*t.second - t.first*s.second, d); ans += ub - lb; if(binary_search(all(vv[2]), ng, les)) { --ans; } } } rep(i, 3) { int j = (i + 1) % 3; each(s, vv[i])each(t, vv[j])if(g(s, t))ans++; } cout << ans << endl; }