import sys input = sys.stdin.readline from decimal import * getcontext().prec = 30 from bisect import bisect_left from math import gcd L=[[0] for i in range(3)] N=int(input()) for i in range(N): p,a,b=map(int,input().split()) GCD=gcd(a,b) a//=GCD b//=GCD L[p].append(Decimal(b)/Decimal(a+b)) L[0].sort() L[1].sort() L[2].sort() ANS=0 SET=set(L[2]) for x in L[0]: for y in L[1]: if x+y>1: break MAX=max(x,y) k=bisect_left(L[2],1-MAX) #print(x,y,L[2],k,1-MAX) ANS+=k z=x+y if z<1-MAX and 1-z in SET: #print(x,y,z) ANS-=1 print(ANS)