// Slower C++ solution:
#include <stdio.h>

#include <string.h>

#include <cstdio>

#include <iostream>

#include <string>

#include <algorithm>

using namespace std;

#define Max 110

#define LL long long



double l[Max], a[Max], b[Max];

double dis[Max][Max], num[Max];

LL temp[Max];



//void init ()

//{

//	LL ans = 0, x;

//	for (LL i = 0;i <= 30;i ++)

//	{

//		x = i;

//		ans = 0;

//		while(x)

//		{

//			if(x % 2 == 1) 

//				ans ++;

//			x /= 2;

//		}

//		num[i] = ans;

//	}

//}





LL judge (LL x)

{

	LL ans = 0;



	while(x)

	{

		if(x % 2 == 1) 

			ans ++;

		x /= 2;

	}

	return ans;

}





double cal(LL x)

{

	double ans = 0.0;

	LL cnt = 0;

	for(LL i = 1; x; i++)

	{

		if(x % 2 == 1)

		{

			temp[++ cnt] = i;

			for(LL j = 1;j < cnt; j++)

			{

				ans += dis[i][temp[j]];

			}

		}

		x /= 2;

	}

	return ans;

}



double MAX(double a, double b)

{return a > b ? a : b;}



int main()

{

	//init ();

	LL n, m, i, j, k;

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

	{

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

		{

			scanf("%lf%lf%lf", &l[i], &a[i], &b[i]);

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

			{

				dis[i][j] = dis[j][i] = (l[i] - l[j]) * (l[i] - l[j]) + (a[i] - a[j]) * (a[i] - a[j]) + (b[i] - b[j]) * (b[i] - b[j]);

			}

		}



		if (m <= 1 || n == 0)

		{

			printf ("0.00000000000000000000\n");

			continue;

		}

		double ans = 0.0;

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

		{

			//if (num[i] == m)

			if (judge (i) == m)

			{

				double temp = cal (i);

				ans = MAX (ans, temp);

			}

		}

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

	}

}

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

}