n, m = gets.split.map(&:to_i)
c = n.times.map{gets.split.map(&:to_f)}
d = Array.new(n).map{Array.new(n)}
n.times do |i|
    n.times do |j|
        d[i][j] = (0..2).map{|k| (c[i][k] - c[j][k])**2}.inject(:+)
    end
end
puts (0...n).to_a.combination(m).map{|c| c.combination(2).map{|p,q| d[p][q]}.inject(:+)}.max || 0