// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <cstdlib>

#include <iostream>

#include <algorithm>

#include <cstdlib>

#include <cstring>

#include <string>

#include <vector>

#include <cstdio>

#include <queue>

#include <stack>

#include <cmath>

#include <time.h>

using namespace std;



#define LL long long 

#define clr(x) memset(x,0,sizeof(x))

#define eps 1e-6

#define PI 3.1415926535897932384626433832795028          

#define MAXN 105



struct color

{

	double a,b,c;



}e[105];



double d[105][105];



int check[1005];



int main()

{

	int n,m;

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

	{

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

			scanf("%lf%lf%lf",&e[i].a,&e[i].b,&e[i].c);



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

		{

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

			{

			    d[i][j]=(e[i].a-e[j].a)*(e[i].a-e[j].a)+(e[i].b-e[j].b)*(e[i].b-e[j].b)+(e[i].c-e[j].c)*(e[i].c-e[j].c);

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

			}

		}

		double s=0,min=0;

		

		clr(check);



		for(int i=n-m;i<n;i++)

		{

			check[i]=1;

		}

		//s=0;

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

			//	printf("%d",check[i]);

			//printf("\n");

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

			{   

				if(check[i])

				{

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

					{

						if(check[j])

							s+=d[i][j];

					}

				}

			}

			//printf("%d\n",s);

			if(s>min)

				min=s;

		while(next_permutation(check,check+n))

		{

			s=0;

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

				//printf("%d",check[i]);

			//printf("\n");

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

			{   

				if(check[i])

				{

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

					{

						if(check[j])

							s+=d[i][j];

					}

				}

			}

			//printf("%d\n",s);

			if(s>min)

				min=s;

		}		

		printf("%lf\n",min);

	}

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.809636631410471x):
#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;

}