def bitCount(i)
  res = 0

  while i > 0 do
    if i % 2 == 1
      res += 1
    end
    i /= 2
  end

  res
end

n, m = gets.chomp.split.map(&:to_i)

l = Array.new(n)
a = Array.new(n)
b = Array.new(n)

n.times do |i|
  l[i], a[i], b[i] = gets.chomp.split.map(&:to_f)
end

ans = 0.0

(1 << n).times do |i|
  if bitCount(i) != m
    next
  end

  sum = 0.0
  
  n.times do |j|
    if (i >> j) % 2 == 0
      next
    end
    n.times do |k|
      if  (i >> k) % 2 == 0 || j >= k
        next
      end
      sum += (l[j] - l[k]) ** 2
      sum += (a[j] - a[k]) ** 2
      sum += (b[j] - b[k]) ** 2
    end
  end

  if sum > ans
    ans = sum
  end
end

puts ans