from collections import defaultdict as dd n = int(input()) X = dd(int) Y = dd(int) for _ in range(n): a, b, t = map(int, input().split()) if a == 0: X[b - t] += 1 else: Y[b - t] += 1 ans = 0 for k, v in X.items(): ans += v * Y[k] print(ans)