def distance(a, b)
  sum = 0
  a.length.times do |idx|
    sum += (a[idx] - b[idx])**2
  end
  Math.sqrt(sum)
end

N, D = gets.split(' ').map(&:to_i)
x = []
N.times do
  x.push(gets.split(' ').map(&:to_i))
end
count = 0
x.combination(2).each do |y, z|
  dist = distance(y, z)
  count += 1 if dist == dist.floor
end
puts count