#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(10);
  int N, M;
  cin >> N >> M;
  vector<double> L(N), a(N), b(N);
  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 (__builtin_popcount(i) == M){
      double sum = 0;
      for (int j = 0; j < N; j++){
        if (i >> j & 1){
          for (int k = j + 1; k < N; k++){
            if (i >> k & 1){
              sum += pow(L[k] - L[j], 2) + pow(a[k] - a[j], 2) + pow(b[k] - b[j], 2);
            }
          }
        }
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}
