input = STDIN.gets.chomp!
N, D = input.split(" ").map!(&:to_i)
tensol = []
ans_num = 0
N.times do |i|
  tensol << STDIN.gets.chomp!.split(" ").map!(&:to_i)
end
tensol.combination(2).to_a.each do |l|
  sum = 0
  D.times do |i|
    sum += (l[0][i] - l[1][i]).abs**2
  end
  if (sum**(1/2.0)).to_s[-2, 2] == ".0" then
    ans_num += 1
  end
end
p ans_num