#include<bits/stdc++.h>
#define rep(i,n) for(i=1;i<=n;i++)
using namespace std;
double dis[30][30];
struct zz{double x1,x2,x3;}co[30];
int n,m;
double ans;
int bitcount(int n) 
{ 
    n = (n &0x55555555) + ((n >>1) &0x55555555) ; 
    n = (n &0x33333333) + ((n >>2) &0x33333333) ; 
    n = (n &0x0f0f0f0f) + ((n >>4) &0x0f0f0f0f) ; 
    n = (n &0x00ff00ff) + ((n >>8) &0x00ff00ff) ; 
    n = (n &0x0000ffff) + ((n >>16) &0x0000ffff) ; 

    return n ; 
}
void dfs(int pre,int comb)
{

	int sum=bitcount(comb);
//	printf("pre=%d comb=%d sum=%d\n",pre,comb,sum); 
	int i,j;
	double tot=0;
	if(sum == m)
	{
		rep(i,n)
			for(j=i+1;j<=n;j++)
				if((comb&(1<<(i-1))) &&(comb&(1<<(j-1))))
					tot+=dis[i][j];
		ans=max(ans,tot);
		return ;
	}
	for(i=pre+1;i<=n;i++)
		dfs(i,comb+(1<<(i-1)));
}
int main()
{
	scanf("%d%d",&n,&m);
	int i,j;
	rep(i,n)
	{
		double x1,x2,x3;
		cin>>x1>>x2>>x3;
		co[i].x1=x1;	co[i].x2=x2;	co[i].x3=x3;
	}
	rep(i,n)
		for(j=i+1;j<=n;j++)
			dis[i][j]=(co[i].x1-co[j].x1)*(co[i].x1-co[j].x1)+(co[i].x2-co[j].x2)*(co[i].x2-co[j].x2)+(co[i].x3-co[j].x3)*(co[i].x3-co[j].x3);
	dfs(0,0);
	printf("%.12f",ans);
	return 0;
}