stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<ctime>

#include<algorithm>

#include<iostream>

#include<string>

#include<cmath>

#include<queue>

#include<vector>

#include<map>

using namespace std;

double Rel[30][30];

struct Point

{

    double x,y,z;

}P[30];

int main()

{

    int s,i,j,M,N;

    double Ans,tmp;

    while (~scanf("%d%d",&N,&M))

    {

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

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

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

        {

            Rel[i][i]=0;

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

                Rel[i][j]=Rel[j][i]=(P[i].x-P[j].x)*(P[i].x-P[j].x)+(P[i].y-P[j].y)*(P[i].y-P[j].y)+(P[i].z-P[j].z)*(P[i].z-P[j].z);

        }

        Ans=0;

        for (s=1;s<(1<<N);s++)

            if (__builtin_popcount(s)==M)

            {

                tmp=0;

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

                    if (s&(1<<i))

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

                            if (s&(1<<j))

                                tmp+=Rel[i][j];

                if (tmp>Ans)

                    Ans=tmp;

            }

        printf("%.15lf\n",Ans);

    }

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#define N 22



double num[N][3];

int choose[N];

double ans;

int n, m;



double sqr(double n) {

	return n * n;

}



double max(double a, double b) {

	return a > b ? a : b;

}



void update() {

	double tmp = 0.0;

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

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

			for (int k = 0; k < 3; k++) {

				tmp += sqr( num[choose[i]][k] - num[choose[j]][k] );

			}

		}

	}

	ans = max(ans, tmp);

}



void DFS(int d, int s) {

	if (m - d > n - s) {

		return;

	} else if (d == m) {

		update();

	} else {

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

			choose[d] = i;

			DFS(d + 1, i + 1);

		}

	}

}



int main () {

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

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

			for (int j = 0; j < 3; j++) {

				scanf ("%lf", &num[i][j]);

			}

		}

		ans = 0.0;

		DFS(0, 0);

		printf ("%.5f\n", ans);

	}

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

ID: qazzaq71

PROG: test

LANG: C++

*/

#include <algorithm>

#include <iostream>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <cstring>

#include <cassert>



using namespace std;



#define REP(a,n) for(int a=0;a<(n);++a)

#define FOR(a,b,c) for(int a=(b);a<=(c);++a)

#define FORD(a,b,c) for(int a=(b);a>=(c);--a)

#define swap(t,a,b) t=a,a=b,b=t

#define min(a,b) (a)<(b)?(a):(b)

#define max(a,b) (a)>(b)?(a):(b)



typedef long long ll;

typedef unsigned long long ull;



int n,m;



double c[50][3];

double maxDist=-1;

int res[50];



void judge(void){

	double dist=0;

	FOR(i,0,m-1)FOR(j,i+1,m-1){

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

				(c[res[i]][1]-c[res[j]][1])*(c[res[i]][1]-c[res[j]][1])+

				(c[res[i]][2]-c[res[j]][2])*(c[res[i]][2]-c[res[j]][2]);

	}

	if(dist>maxDist)maxDist=dist;

}

void dfs(int k,int cur){

	if(k==m){

		judge();

		return ;

	}

	FOR(i,cur,n-1){

		res[k]=i;

		dfs(k+1,i+1);

	}

}

int main(){

#ifdef DEBUG

	FILE * ptrFILE=freopen("a.txt","r",stdin);

	assert(ptrFILE!=NULL);

#endif

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

	memset(c,0,sizeof(c));

	FOR(i,0,n-1)

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

	maxDist=-1;

	dfs(0,0);

	printf("%f\n",maxDist);

    return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <cmath>

#include <cstdio>

#include <cstdlib>

#include <queue>

#include <vector>

#include <stack>

#include <set>

#include <map>

#include <string>

#include <cctype>

#include <cstring>

#include <string>

#include <numeric>

#include <functional>

#include <iomanip>

#include <ctime>



using namespace std;



typedef long long LL;

typedef unsigned long long uLL;



struct NODE

{

    double x,y,z;

}nd[22];

int n,m;

double res;

double dis[22][22];

int pik[22];

int len;

void DFS(int u,int last)

{

    if(u==m)

    {

        double sum=0;

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

        {

            int x=pik[i];

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

            {

                int y=pik[j];

                sum+=dis[x][y];

            }

        }

        if(res<sum)res=sum;

        return ;

    }

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

    {

        pik[u]=i;

        DFS(u+1,i+1);

    }

}



int main()

{

	while(~scanf("%d%d",&n,&m))

	{

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

	    {

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

	    }

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

	    {

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

	        {

	            dis[i][j]=(nd[i].x-nd[j].x)*(nd[i].x-nd[j].x)+(nd[i].y-nd[j].y)*(nd[i].y-nd[j].y)+(nd[i].z-nd[j].z)*(nd[i].z-nd[j].z);

	        }

	    }

	    res=0;

	    DFS(0,0);

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

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cmath>

#include <cstring>

#include <algorithm>



#define INF 0x7fffffff

#define MOD 10000007

#define N 30



using namespace std;



struct node

{

      double a,b,c;

} color[N];

int ans[N];

int n,m;

double Min;



double squr(double a,double b,double c)

{

      return a*a+b*b+c*c;

}

void dfs(int now,int tot)

{

      if(tot==m)

      {

            double cnt=0.0;

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

            {

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

                  {

                        double aa=fabs(color[ans[i]].a-color[ans[j]].a);

                        double bb=fabs(color[ans[i]].b-color[ans[j]].b);

                        double cc=fabs(color[ans[i]].c-color[ans[j]].c);

                        cnt=cnt+squr(aa,bb,cc);

                  }

            }

            if(cnt>Min) Min=cnt;

            return;

      }

      if(m-tot>n-now+1) return;

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

      {

            ans[tot+1]=i;

            dfs(i+1,tot+1);

      }

}

int main()

{

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

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

      {

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

      }

      memset(ans,0,sizeof(ans));

      Min=0.0;

      dfs(1,0);

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

      return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<vector>

#include<cmath>

using namespace std;

struct node

{

	double x,y,z;

};

struct node x[21];

vector<double>a;

int b[25],i,n,m,j;

double d[21][21],maxx=0,ans;



double dis(int i,int j)

{

 return 

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

}

void dfs(int v,int k)

{

	int x,i,j,t;

 b[v]=1;

 if(k==m)

 {

	ans=0;

	for(i=0;i<a.size();i++)

	{

		x=a[i];

		for(j=0;j<a.size();j++)

			if(j!=i)

			{

				t=a[j];

				ans=ans+d[x][t];

			}

	}

	if(ans/2>maxx)maxx=ans/2;

	return;

 }

 a.push_back(v); k++;

 if(v+1<=n)dfs(v+1,k);

 a.pop_back(); k--;

 if(v+1<=n)dfs(v+1,k);

 b[v]=0;

}

int main()

{

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

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

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

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

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

			d[i][j]=dis(i,j);

	dfs(0,0);

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

	return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
# include <math.h>

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

# include <algorithm>

# include <iostream>



# define For(i,x,y)   for((i)=(x);i<(y);(i)++)

# define MAX(x,y)   ((x)>(y)? (x):(y))

# define MIN(x,y)   ((x)<(y)? (x):(y))

# define sz(a)      (sizeof(a))

# define mem(a)     (memset((a),0,sizeof(a)))



# define fop freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);

# define print(x) (printf("%d\n",x))

# define scan(x) (scanf("%d",&x))

# define printc(x) (printf("%c\n",x))

# define scanc(x) (scanf("%c",&x))

# define INF 0x7fffffff



using namespace std;

typedef long long           ll;

int v[25],m,n;

double a[25],b[25],c[25],d[25][25],ans;

int dfs(int i,int j,double x)

{

    int k;

    double kk=0;

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

    if (j>=m)

    {



        if (x>ans) ans=x;

        return 0;

    }

    if (i>n) return 0;

    v[i]=1;

    For (k,1,n+1)

      if (v[k]) kk+=d[i][k];

    dfs(i+1,j+1,x+kk);

    v[i]=0;

    dfs(i+1,j,x);

    return 0;

}

int main()

{

    int i,j;

    scan(n);scan(m);

    mem(v);

    For(i,1,n+1)

    {

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

    }

    For (i,1,n+1)

      For (j,1,n+1)

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

    dfs(1,0,0);

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

    return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <vector>

#include <list>

#include <map>

#include <set>

#include <deque>

#include <stack>

#include <memory.h>

#include <bitset>

#include <algorithm>

#include <functional>

#include <numeric>

#include <utility>

#include <sstream>

#include <iostream>

#include <iomanip>

#include <cstdio>

#include <cmath>

#include <cstdlib>

#include <ctime>

#include <cstring>



using namespace std;











int i,j;

int nn,mm;

double l[100];

double a[100];

double b[100];

double core[100][100];



int s[100];

double maxx=0.0;

void print(int N)

{

     double num=0.0;

for(int ii=1;ii<=N;ii++)

{

 for(int jj=1;jj<=N;jj++)

{

 //printf("ii=%d jj=%d\n",s[ii],s[jj]);

 num+=core[s[ii]][s[jj]];

}

//printf("\n");

}

 if(num>maxx){maxx=num;}

}

void zuhe(int a,int n,int M,int N)

{

if(n<=N)

{

int i;

for(int ii=a;ii<=M-N+n;ii++)

{

s[n]=ii;

if(n==N)

print(N);

else

zuhe(a+1,n+1,M,N);

a++;

}

}

}







int main()

{

scanf("%d%d",&nn,&mm);

if(mm==1){printf("0.00000000000000000000\n");return 0;}

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

{

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

}

int topp=0;



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

{

               // printf("%.20f\n",(l[i]*l[i]+a[i]*a[i]+b[i]*b[i]));

}



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

{

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

    {

       

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

       //printf("%.2f ",core[i][j]);

       

    }

    //printf("\n");

}

zuhe(1,1,nn,mm);

printf("%.20f\n",maxx/2);



//system("pause");

    return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

	}

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

#include <cstdlib>

#include <cstring>

#include <string>

#include <vector>

#include <cstdio>

#include <queue>

#include <cmath>

#include <string.h>

#include <assert.h>

#include <stack>

#define PI 3.1415926535897932384626433832795028



using namespace std;

struct point 

{

	double x,y,z;

}a[30];

int n,m,num[1000];

double map[100][100];

double f()

{

	double k=0;

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

	{

		if(num[i]==0)

		{

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

			{

				if(num[j]==0&&i!=j)

				{

					k+=map[i][j];

				}

			}

		}

	}

	return k;

}

int main()

{

	int i,j,nx,ny,k;

	double max1,max2,sum,ans,temp;

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

	{

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

		{

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

		}

		if(m==1)

		{

			printf("0.00000000000000000000\n");

			continue;

		}

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

		{

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

			{

				if(i!=j)

				{

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

				}

			}

		}

		ans=0;

		for(int j=(1<<m)-1;j<1<<n;j++)

		{							    

			memset(num,1,sizeof(num));

			int count=0;

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

			{

				if(j&(1<<i))  num[i]=0,count++;

			}

			if(count==m)

			{

				temp=f();

				if(temp>ans) 

					ans=temp;

			}

		}

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

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#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;   

}

// Fastest known solution for this problem: