N, D = gets.split(' ').map(&:to_i)

dots = []
cnt = 0

N.times do
  dots.push(gets.split(' ').map(&:to_i))
end

(N - 1).times do |i|
  (N - 1).step(i + 1, -1) do |j|
    distance = 0
    D.times do |idx|
      distance += (dots[i][idx] - dots[j][idx])**2
    end
    distance = Math.sqrt(distance)
    cnt += 1 if distance == distance.to_i
  end
end

print cnt
