require 'complex'
n, d = gets.split(" ").map(&:to_i)
dat = []
count = 0
pla = []

n.times do |i|
  dat << gets.split(" ").map(&:to_i)
end

for j in 0..(n-1) do 
  for k in j+1..(n-1) do
    if j != k
      for l in 0..(d-1) do
        pla << (dat[j][l]-dat[k][l])**2
      end
      #puts pla
      res = Math.sqrt(pla.inject(:+))
      #puts res
      if (/^[+-]?[0-9]*[\.]?[0]*$/ =~ res.to_s)
        count += 1
      end
      pla.slice!(0..d-1)
    end   
  end
end
puts count
