n, _ = gets.split(" ").map(&:to_i)
xs = []

n.times { xs << gets.split(" ").map(&:to_i) }

count = 0

xs.slice(0, xs.size - 1).each_with_index do |y, i|
  xs.slice(i + 1, xs.size).each do |z|
    count += 1 if Math.sqrt(y.zip(z).inject(0) do |r, (yy, zz)|
      r + (yy - zz) ** 2
    end).to_s =~ /\A[0-9]+\.0\z/
  end
end

puts count
