input = readlines()

n, d = input.shift.chomp.split("\s").map{|x| x.to_i}

coords = []
input.each do |l|
  vals = l.chomp.split("\s").map{|x| x.to_i}
  coords.push(vals)
end

cnt = 0
coords.each_with_index do |v1, i1|
  coords.each_with_index do |v2, i2|
    next if i1 >= i2
    sum = 0
    v1.each_with_index do |x1, i3|
      sum += (x1 - v2[i3])**2
    end
    cnt += 1 if Math.sqrt(sum) == Math.sqrt(sum).to_i
  end
end

puts cnt
