#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

double dfs(vector<int> V, vector< vector<double> > &D, int N, int M, int t, int i, double ret){
  if(N - i < M - t) return 0.0;
  if(t == M) return ret;
  double r = ret;
  for(int j = 0; j < t; ++j)
    r += D[i][V[j]];
  if(N - i >= M - t) ret = dfs(V,D,N,M,t,i+1,ret);
  V.push_back(i);
  ret = max(ret,dfs(V,D,N,M,t+1,i+1,r));
  return ret;
}

int main(){
  int N, M;
  cin >> N >> M;
  double L[N], a[N], b[N];
  for(int i = 0; i < N; ++i){
    cin >> L[i] >> a[i] >> b[i];
  }
  vector< vector<double> >  D(N,vector<double>(N));
  for(int i = 0; i < N; ++i){
    D[i][i] = 0.0;
    for(int j = i+1; j < N; ++j){
      D[i][j] = (L[i]-L[j])*(L[i]-L[j]) + (a[i]-a[j])*(a[i]-a[j]) + (b[i]-b[j])*(b[i]-b[j]);
      D[j][i] = D[i][j];
    }
  }

  vector<int> V;
  printf("%.10f\n",dfs(V,D,N,M,0,0,0.0));
  return 0;
}