from collections import defaultdict N = int(input()) L = [list(map(int,input().split())) for _ in range(N)] A,B,T = [list(i) for i in zip(*L)] dic = defaultdict(int) for i in range(N): if A[i] == 0: dic[B[i]-T[i]] += 1 ans = 0 for i in range(N): if A[i] == 1: ans += dic[B[i]-T[i]] print(ans)