#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
if m<2 then p 0;exit end
a=[];n.times{a.push(gets.split.map(&:to_f))}
i=0
f=0
a.combination(m){|b|
	f0=0
	b.combination(2){|e|
		f0+=(e[0][0]-e[1][0])**2+(e[0][1]-e[1][1])**2+(e[0][2]-e[1][2])**2
	}
	if f<f0 then f=f0 end
}
p f