from collections import defaultdict n = int(input()) red_d = defaultdict(int) # 赤い点の B_i - T_i を記録する blue_l = [] # 青い点の B_j - T_j を保存する for _ in range(n): a, b, t = map(int, input().split()) if a == 0: red_d[b - t] += 1 else: blue_l.append(b - t) ans = 0 # 答え for i in blue_l: # 青い点すべてについて、B_j - T_j = B_i = T_i なる i の数を数えて足す ans += red_d[i] print(ans)