import sys input = sys.stdin.readline N=int(input()) R=[0]*1000000 B=[0]*1000000 for i in range(N): a,b,t=map(int,input().split()) if a==0: R[b-t+300000]+=1 else: B[b-t+300000]+=1 ANS=0 for i in range(len(R)): ANS+=R[i]*B[i] print(ANS)