// Slower C++ solution:
/*#include<cstdio>

#include<cstring>

#include<cmath>

#include<cstdlib>

#include<cctype>

#include<iostream>

#include<algorithm>

#include<stack>

#include<queue>

#include<list>

#include<vector>

#include<deque>

using namespace std;

const int MAXN=30;

const double EPS=1e-8;

double a[MAXN][4];

double dist[MAXN][MAXN];

int flag[MAXN];

int n,m;

double res;

double dblcmp(double x){

    if(fabs(x)<EPS){

        return 0;

    }

    return x>0?1:-1;

}

double max(double a,double b){

    return dblcmp(a-b)>=0?a:b;

}

double check(){

    double res=0.0;

    for(int i=0;i<n;i++){

        if(flag[i]==-1){

            continue ;

        }

        for(int j=i+1;j<n;j++){

            if(flag[j]!=-1){

                res+=dist[i][j];

            }

        }

    }

    return res;

}

void dfs(int k,int step){

    if(step>=m){

        double t=check();

        res=max(res,t);

        return ;

    }

    if(k>=n){

        return ;

    }

    if(n-k+step<m){

        return ;

    }

    flag[k]=k;

    dfs(k+1,step+1);

    flag[k]=-1;

    dfs(k+1,step);

}

int main(){

    freopen("A.in","r",stdin);

    while(scanf("%d%d",&n,&m)==2){

        for(int i=0;i<n;i++){

            scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

        }

        for(int i=0;i<n;i++){

            for(int j=i+1;j<n;j++){

                dist[i][j]=(a[i][0]-a[j][0])*(a[i][0]-a[j][0])+

                (a[i][1]-a[j][1])*(a[i][1]-a[j][1])+(a[i][2]-a[j][2])*(a[i][2]-a[j][2]);

            }

        }

        memset(flag,-1,sizeof(flag));

        res=0.0;

        dfs(0,0);

        printf("%.20lf\n",res);

    }

    return 0;

}*/

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<cctype>

#include<iostream>

#include<algorithm>

#include<stack>

#include<queue>

#include<deque>

#include<list>

#include<vector>

using namespace std;

const int MAXN=30;

const double EPS=1e-8;

double a[MAXN][4];

double dist[MAXN][MAXN];

int s[MAXN];

double res;

int top;

int n,m;

double check(){

    double res=0.0;

    for(int i=1;i<=top;i++){

        for(int j=i+1;j<=top;j++){

            res+=dist[s[i]][s[j]];

        }

    }

    return res;

}

void dfs(int k){

    if(top>=m){

        double t=check();

        res=max(res,t);

        return ;

    }

    if(k>=n){

        return ;

    }

    if(top+n-k<m){

        return ;

    }

    s[++top]=k;

    dfs(k+1);

    top--;

    dfs(k+1);

}

int main(){

    //freopen("A.in","r",stdin);

    while(scanf("%d%d",&n,&m)==2){

        for(int i=0;i<n;i++){

            scanf("%lf%lf%lf",&a[i][0],&a[i][1],&a[i][2]);

        }

        for(int i=0;i<n;i++){

            for(int j=i+1;j<n;j++){

                dist[i][j]=(a[i][0]-a[j][0])*(a[i][0]-a[j][0])+

                (a[i][1]-a[j][1])*(a[i][1]-a[j][1])+

                (a[i][2]-a[j][2])*(a[i][2]-a[j][2]);

            }

        }

        res=0.0;

        top=0;

        dfs(0);

        printf("%.20lf\n",res);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.7958000423563165x):
#include<cmath>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

using namespace std;

const double eps = 1e-10;

const int N=25;



struct point {

    double x,y,z;

}pt[N];

int n,m;

double dis[N][N];



double dist(point p1,point p2) {

    return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z);

}



double ret;

int ans[N];

void dfs(int idx,int k,double sum) {

    if(k+(n-idx)+2<m) return;

    if(k==m) {

        ret=max(ret,sum);

        return;

    }



    dfs(idx+1,k,sum);

    double tmp=0;

    for(int i=0;i<k;i++) tmp+=dis[ans[i]][idx];

    ans[k]=idx;

    dfs(idx+1,k+1,sum+tmp);

}



int main()

{

    int i,j,t,cas=0;

    while(scanf("%d%d",&n,&m)!=EOF) {

        for(i=1;i<=n;i++) {

            scanf("%lf%lf%lf",&pt[i].x,&pt[i].y,&pt[i].z);

        }

        for(i=1;i<=n;i++) {

            for(j=1;j<=n;j++) {

                dis[i][j]=dist(pt[i],pt[j]);

            }

        }



        ret=0.0;

        dfs(1,0,0);



        printf("%.10f\n",ret);

    }

    return 0;

}



/*

20 10

0 0 0

1 1 1

2 2 2

3 3 3

4 4 4

5 5 5

6 6 6

7 7 7

8 8 8

9 9 9

10 10 10

11 11 11

12 12 12

13 13 13

14 14 14

15 15 15

16 16 16

17 17 17

18 18 18

19 19 19

*/