n,d = gets.chomp.split(' ').map(&:to_i)
arr = []
i = 0
while i < n
  a = gets.chomp.split(' ').map(&:to_i)
  arr << a
  i += 1
end
# p arr
answers = []
i = 0
while i < n
  j = i+1
  while j < n
    k = 0
    ans = 0
    while k < d
      ans += (arr[i][k] - arr[j][k])**2 
      k += 1
    end
    answers << Math.sqrt(ans)
    j += 1
  end
  i += 1
end
# p answers
count = 0
i = 0
while i < answers.size
  if answers[i] % 1 == 0
    count += 1
  end
  i += 1
end
puts count