import sys input = sys.stdin.readline from bisect import bisect 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(b/(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(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)