require 'mathn'

n, d = gets.split.map(&:to_i)
x = []
n.times do
  x << gets.split.map(&:to_i)
end

ans = 0
(0..n -1).to_a.combination(2) do |c|
  i = c[0]
  j = c[1]
  next unless i < j

  dist = 0
  d.times do |k|
    dist += (x[i][k] - x[j][k]) ** 2
  end
  ans += 1 if Math.rsqrt(dist).kind_of?(Integer)
end

puts ans
