#include using namespace std; using ll=long long; const int N=4005; const long double eps=1e-17; int n; vector t[3]; ll ans; int main(){ scanf("%d",&n); t[0].push_back(1);t[1].push_back(1);t[2].push_back(1); for(int i=1;i<=n;++i){ int p,a,b; scanf("%d%d%d",&p,&a,&b); t[p].push_back(a/(long double)(a+b)); } sort(t[0].begin(),t[0].end()); sort(t[1].begin(),t[1].end()); sort(t[2].begin(),t[2].end()); for(long double l0:t[0]){ for(long double l1:t[1]){ long double mx=max(1-l0,1-l1); long double jd=2-l0-l1; if(jd>1+eps)continue; int it1=lower_bound(t[2].begin(),t[2].end(),mx-eps)-t[2].begin(); int it2=lower_bound(t[2].begin(),t[2].end(),jd-eps)-t[2].begin(); ans+=t[2].size()-it1; if(fabs(t[2][it2]-jd)1+eps)continue; int it1=lower_bound(t[1].begin(),t[1].end(),mx-eps)-t[1].begin(); int it2=lower_bound(t[1].begin(),t[1].end(),jd-eps)-t[1].begin(); ans+=t[1].size()-it1; if(fabs(t[1][it2]-jd)1+eps)continue; int it1=lower_bound(t[0].begin(),t[0].end(),mx-eps)-t[0].begin(); int it2=lower_bound(t[0].begin(),t[0].end(),jd-eps)-t[0].begin(); ans+=t[0].size()-it1; if(fabs(t[0][it2]-jd)