#include <bits/stdc++.h>
int main() {
	int N, M;
	std::cin >> N>> M;
	std::vector<double> A(N),B(N),C(N);
	for(int i = 0; i < N; i++){std::cin >> A[i]>>B[i]>>C[i];}
	auto dist = [&](const int i, const int j){
		return (A[i]-A[j])*(A[i]-A[j])+(B[i]-B[j])*(B[i]-B[j])+(C[i]-C[j])*(C[i]-C[j]);
	};
	std::vector<int> o(N, 0);
	std::fill(o.begin(),o.begin()+M, 1);
	double ans = 0;
	do{
		std::vector<int> ind;
		for(int i = 0;i < N; i++){
			if(o[i]){ind.push_back(i);}
		}
		double sum = 0;
		for(int i = 0;i < M-1; i++){
			for(int j = i+1; j < M; j++){sum += dist(ind[i],ind[j]);}
		}
		ans = std::max(ans, sum);
	}while(std::prev_permutation(o.begin(),o.end()));
	std::cout << std::fixed << std::setprecision(15)<<ans << std::endl;
	return 0;
}
