N = int(input()) C = {} D = {} for _ in range(N): a,b,t = map(int,input().split()) if a==0: C[t-b] = C.get(t-b,0)+1 else: D[t-b] = D.get(t-b,0)+1 ans = 0 for x in C: ans += C[x]*D.get(x,0) print(ans)