import sys input = sys.stdin.readline from bisect import bisect_left from collections import Counter from math import gcd L=[[(0,1)] for i in range(3)] N=int(input()) for i in range(N): p,a,b=map(int,input().split()) G=gcd(a,b) L[p].append((b//G,(a+b)//G)) from functools import cmp_to_key def cmp(a, b): if a[0]*b[1]>b[0]*a[1]: return 1 elif a[0]*b[1]==b[0]*a[1]: return 0 else: return -1 L[0].sort(key=cmp_to_key(cmp)) L[1].sort(key=cmp_to_key(cmp)) L[2].sort(key=cmp_to_key(cmp)) ANS=0 C=Counter(L[2]) for x0,x1 in L[0]: for y0,y1 in L[1]: if x0*y1+x1*y0>x1*y1: break if x0*y1>x1*y0: MAX=(x0,x1) else: MAX=(y0,y1) m0,m1=MAX OK=-1 NG=len(L[2]) while NG>OK+1: mid=(OK+NG)//2 z0,z1=L[2][mid] if z0*m1<=(m1-m0)*z1: OK=mid else: NG=mid #print(x0,x1,y0,y1,L[2],OK) ANS+=OK+1 z0=x0*y1+x1*y0 z1=x1*y1 G=gcd(z0,z1) z0//=G z1//=G #print((z1-z0,z1),z0*m1,(m1-m0)*z1) if (z1-z0)*m1<=(m1-m0)*z1 and (z1-z0,z1) in C: ANS-=C[(z1-z0,z1)] #print("!",x0,x1,y0,y1,MAX,z0,z1,C[(z0,z1)]) print(ANS)