#include using namespace std; class rational{ public: bool isMinus; long long denominator; long long numerator; rational(long long a,long long b){ if(a<0){ a=-a; b=-b; } if(b==0){ denominator=1; numerator=0; }else{ long long p,q,temp; p=max(a,abs(b)); q=min(a,abs(b)); while(q>0){ temp=q; q=p%q; p=temp; } denominator=a/p; numerator=b/p; } } rational operator + (rational a){ return rational(a.denominator*denominator,denominator*a.numerator+a.denominator*numerator); } rational operator - (rational a){ return rational(a.denominator*denominator,-denominator*a.numerator+a.denominator*numerator); } bool operator > (rational a){ return numerator*a.denominator>a.numerator*denominator; } bool operator >= (rational a){ return numerator*a.denominator>=a.numerator*denominator; } bool operator < (rational a){ return numerator*a.denominatorb){ return a; }else{ return b; } } int main(){ int N; cin>>N; vector> lines(3,vector(1,rational(1,0))); int p; long long ans=0; long long a,b; for(int i=0;i>p>>a>>b; lines[p].push_back(rational((b+a),b)); } for(int i=0;i<3;i++){ sort(lines[i].begin(),lines[i].end(),[](rational a,rational b){return a& a,vector& b){return a.size()rational(1,1)){ continue; } m=0; M=lines[2].size(); while(M-m>1){ mid=(m+M)/2; if(lines[2][mid]+lines[0][i]+lines[1][j]>rational(1,1)){ M=mid; }else{ m=mid; } } if(lines[2][m]+lines[0][i]+lines[1][j]==rational(1,1)){ ans-=1; } m=-1; M=lines[2].size(); while(M-m>1){ mid=(m+M)/2; if(lines[2][mid]+max(lines[0][i],lines[1][j])>rational(1,1)){ M=mid; }else{ m=mid; } } ans+=m+1; } } cout<