from collections import Counter N=int(input()) B=[[],[]] for i in range(N): a,b,t=map(int,input().split()) b-=t B[a].append(b) cnt=Counter(B[0]) ans=sum(cnt[b] for b in B[1]) print(ans)