// 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.7901944652872706x):
#include <stdio.h>

#define MAXN (1<<21)

double f[1050000];

double map[21][21],x[21],y[21],z[21];

int num(int a)

{

    int ans=0;

    for(int i=0;i<20;i++)

        if((a>>i)&1)

            ans++;

    return ans;

}

int main()

{

    int n,m,i,j,a,b,t;



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

    {

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

        {

            scanf("%lf%lf%lf",x+i,y+i,z+i);

        }

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

            for(map[i][i]=0,j=0;j<i;j++)

                map[i][j]=map[j][i]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]);



        int temp;

        double ans=0;



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

        {

            f[i]=0;

            temp=num(i);

            //printf("%d %d\n",i,temp);

            if(temp==1)

                    f[i]=0;

            else if(temp==2){

               // puts("!");

                for(t=j=0;j<20;j++)

                {

                    if((i>>j)&1)

                    {

                        if(t==0)

                            a=j,t=1;

                        else

                            b=j;

                    }

                }



                f[i]=map[a][b];// printf("%d %d %d\n\n",a,b,f[i]);

            }

            else{

                for(j=0;j<20;j++)

                {

                    if((i>>j)&1)

                        f[i]+=f[i-(1<<j)];

                }

                f[i]/=(double)(temp-2);

            }

           // printf("%d %lf\n\n",i,f[i]);

            if(temp==m&&ans<f[i])

                    ans=f[i];

        }



        printf("%.10lf\n",ans);

    }

    return 0;

}