#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

// #define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back 
typedef long double ld;

ld calcds(ld l1,ld a1,ld b1,ld l2, ld a2, ld b2){
  return (l1-l2)*(l1-l2)+(a1-a2)*(a1-a2)+(b1-b2)*(b1-b2);
}
int main(){
  ld ans = 0.0;
  int m,n;
  cin >> n >> m;
  vector<long double>l,a,b;
  REP(i,n){
    long double ll,aa,bb;
    cin >> ll >> aa >> bb;
    l.pb(ll); a.pb(aa); b.pb(bb);
  }
  int tmp[1000];
  int cnt = 0;
  REP(i,n) tmp[i] = 1;
  REP(i,n-m) tmp[i] = 0;
  do {
    cnt++;
    ld sum = 0.0;
    REP(i,n){
      FOR(j,i,n){
        if(tmp[i]==1&&tmp[j]==1){
          sum += calcds(l[i],a[i],b[i],l[j],a[j],b[j]);
        }
      }
    }
    ans = max(ans,sum);
  } while ( next_permutation (tmp,tmp+n));
  cout << fixed << setprecision(25) << ans << endl;
  return 0;
}