#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int N,M;
double x[30],y[30],z[30],ans=0;
double calc(int a,int b){
  return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])+(z[a]-z[b])*(z[a]-z[b]);
}
int main(){
  cin>>N>>M;
  for(int i=0;i<N;i++)cin>>x[i]>>y[i]>>z[i];
  for(int i=0;i<(1<<N);i++){
    if(__builtin_popcount(i)!=M)continue;
    double sum=0;
    for(int j=0;j<N;j++){
      if((i>>j&1)==0)continue;
      for(int k=j+1;k<N;k++){
	if((i>>k&1)==0)continue;
	sum+=calc(j,k);
      }
    }
    ans=max(ans,sum);
  }
  printf("%.8f\n",ans);
  return 0;
}