#include<cstdio>
#include<algorithm>
using namespace std;

double a[20],b[20],c[20];
double dist[20][32];
double squ(double x){return x*x;}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%lf %lf %lf",a+i,b+i,c+i);
	}
	if(m==0){
		printf("%.5f\n",0.);
		return 0;
	}
	for(int i=0;i<n;i++)
 		for(int j=i+1;j<n;j++)
 			dist[i][j]=squ(a[i]-a[j])+squ(b[i]-b[j])+squ(c[i]-c[j]);
	double ans=0;
	int comb = (1 << m) - 1;
	while (comb < 1 << n) {
		double sum=0;
 		for(int i=0;i<n;i++){
 			if((comb>>i&1)^1)continue;
 			for(int j=i+1;j<n;j++){
 				if(comb>>j&1)sum += dist[i][j];
 			}
 		}
		ans=max(ans,sum);
  		int x = comb & -comb, y = comb + x;
  		comb = ((comb & ~y) / x >> 1) | y;
	}
	printf("%.5f\n",ans);
	return 0;
}