N,D = gets.split.map(&:to_i)
X = []

(1..N).each do |n|
  X << gets.split.map(&:to_i)
end

count = 0

X.each_with_index do |x, i|
  (i+1...N).each do |y|
    temp = 0
    D.times do |d|
      temp += (x[d] - X[y][d]) ** 2
    end
    count += 1 if Math.sqrt(temp).to_s =~ /^[0-9]+.0$/
  end
end

puts count