N = int(input()) R = {} B = {} for i in range(N): c,a,b = map(int,input().split()) if c: if a-b not in R: R[a-b] = 0 R[a-b] += 1 else: if a-b not in B: B[a-b] = 0 B[a-b] += 1 ans = 0 for k,v in R.items(): if k in B: ans += R[k] * B[k] print(ans)