n,d = gets.chop.split.map(&:to_i)

points = Array.new(n).map{Array.new()}

for i in 0..n-1 
  points[i] = gets.chop.split.map(&:to_i)
end

count = 0
for i in 0..n-1
  for j in 0..n-1
    if i >= j
      next
    end

    sum = 0.0
    for k in 0..d-1
      sum += (points[j][k] - points[i][k]) * (points[j][k] - points[i][k])
    end

    if (/^[+-]?[0-9]+\.0$/ =~ Math.sqrt(sum).to_s)
        count += 1
    end
  end
end

puts count