N = gets.to_i v_counter = Hash.new(0) h_counter = Hash.new(0) N.times do a, b, t = gets.split.map(&:to_i) if a == 0 v_counter[b + t] += 1 else h_counter[b + t] += 1 end end ans = 0 v_counter.each do |t, cnt| ans += h_counter[t] * cnt end puts ans