#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

class S{
public:
  double a, b, c;
  S(){}
  S(double a, double b, double c) : a(a), b(b), c(c) {}
};

vector<S> input;
bool data[20];
int n, m;
double ans;

double sq(double a, double b){
  return (a - b) * (a - b);
}

void calc(int p, int cnt){
  if(p == n){
    double sum = 0.0;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        if(data[i] && data[j]){
          sum += sq(input[i].a, input[j].a) + sq(input[i].b, input[j].b) + sq(input[i].c, input[j].c);
        }
      }
    }
    ans = max(ans, sum);
  }else{
    if(cnt < m){
      data[p] = true;
      calc(p+1, cnt+1);
      data[p] = false;
    }
    calc(p+1, cnt);
  }
}

int main(){
  cin >> n >> m;
  fill(data, data+20, false);
  for(int i=0;i<n;i++){
    S in;
    cin >> in.a >> in.b >> in.c;
    input.push_back(in);
  }
  ans = 0.0;
  calc(0, 0);
  printf("%.10f\n", ans);
}