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

#include<stdlib.h>

#include<string.h>

#define maxn 25



struct node 

{

       double x,y,z;

}a[maxn];

double dis[maxn][maxn];

int n,m;

int visit[maxn],use[maxn];

double ans;



double cal(struct node p,struct node q)

{

       return (p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y)+(p.z-q.z)*(p.z-q.z);

}



void judge()

{

     int i,j;

     double tmp=0;

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

         for (j=i+1;j<=m;j++)

             tmp+=dis[use[i]][use[j]]; 

     if (ans-tmp<0.000001)

        ans=tmp;    

}



void updata(int k,int p)

{

     int i;

     

     if (k==m+1)

     {

              judge();

              return;

     }

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

         if (!visit[i])

         {

            visit[i]=1;

            use[k]=i;

            updata(k+1,i+1);

            visit[i]=0;

         }

}

int main()

{

    scanf("%d %d",&n,&m);

    int i,j;

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

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

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

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

        {

            dis[i][j]=cal(a[i],a[j]);

            dis[j][i]=dis[i][j];

        }

    updata(1,1);

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

    return 0;   

}