#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
double L[21],a[21],b[21];
int n,m;
int bit_count(int bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

double comp(int k) {
  vector <int> lab;
    for(int i=0;i<n;i++)
    if((k&(1<<i)) != 0) lab.push_back(i);

  double sum = 0;
  for(int i=0;i<lab.size();i++)
    for(int j=i+1;j<lab.size();j++) {
      double x = L[lab[i]] - L[lab[j]];
      double y = a[lab[i]] - a[lab[j]]; 
      double z = b[lab[i]] - b[lab[j]]; 
      double xyz = x*x + y*y + z*z;
      sum += xyz;
    }
  return sum;
}

int main() {
  cin >> n >> m;
  for(int i=0;i<n;i++) cin >> L[i] >> a[i] >> b[i];

  double ans = 0;
  for(int i=0;i<(1<<n);i++)
    if(bit_count(i) == m) ans = max(ans,comp(i));

  printf("%.15f\n",ans);

  return 0;
}