n, m = gets.split.map(&:to_i)
colors = (1..n).map { gets.split.map(&:to_f) }
dist = (0..n-1).map do |i|
  (0..n-1).map do |j|
    colors[i].zip(colors[j]).map {|x, y| (x - y) ** 2 }.inject(:+)
  end
end

sum = [0]
(1..(1<<n)-1).each do |x|
  i = 0
  i += 1 until x[i] == 1
  y = x - (1 << i)
  sum[x] = sum[y]
  (0..n-1).each do |j|
    sum[x] += dist[i][j] if y[j] == 1
  end
end

answer = (0..(1<<n)-1).select {|x| x.to_s(2).count(?1) == m }.map {|x| sum[x] }.max
printf("%.7f\n", answer)
