from collections import defaultdict N = int(input()) d1 = defaultdict(int) d2 = defaultdict(int) for _ in range(N): A, B, T = map(int, input().split()) if A == 0: d1[B-T] += 1 else: d2[B-T] += 1 ans = 0 for k, v in d1.items(): ans += v * d2.get(k, 0) print(ans)