#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int n,m;
double l[20],a[20],b[20];
double difTable[20][20];
double d[1<<20]; // max distance


double getDif(int i, int j){
  double ll=l[i]-l[j], aa=a[i]-a[j], bb=b[i]-b[j];
  return ll*ll + aa*aa + bb*bb;
}

double cal( const int num ){
  if( d[num] > 0.0 || fabs(d[num])<1e-6 )
    return d[num];

  double ret=0.0;
  for( int shiftIndex=0;shiftIndex<n;shiftIndex++ ){
    int shift = 1<<shiftIndex;
    if( num & shift ){
      int prevValue = num-shift;
      double prev = cal( prevValue );
      for( int i=0;i<n;i++ ){
	if( prevValue & (1<<i) ){
	  prev += getDif( shiftIndex, i );
	}
      }
      ret = max( ret, prev );
    }
  }
  return d[num] = ret;
}


int main(){
  cin >> n >> m;

  for( int i=0;i<n;i++ )
    cin >> l[i] >> a[i] >> b[i];

  int len=1<<n;
  for( int i=0;i<len;i++ )
    d[i] = -1.0;
  d[0] = 0.0;
  for( int i=0;i<n;i++ ){
    difTable[i][i] = 0.0;
    d[1<<i] = 0.0;
    for( int j=i+1;j<n;j++ )
      difTable[i][j] = getDif( i, j );
  }

  double ans=0.0;
  if( m > 1 ){
    for( int i=1;i<len;i++ ){
      int sum=0;
      for( int j=0;j<20;j++ )
	if( i&(1<<j) )sum++;
      if( sum==m )
	ans = max( ans, cal(i) );
    }
  }

  printf("%.10lf\n",ans);

  return 0;
}