from collections import defaultdict n=int(input()) red=defaultdict(int) blue=[] for _ in range(n): a,b,t=map(int,input().split()) if a==0: red[b-t]+=1 else: blue.append(b-t) ans=0 for i in blue: ans+=red[i] print(ans)