stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
# 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;

}

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

}
// Slower C++ solution:
#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;

}

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

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

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<cmath>

#include<algorithm>

using namespace std;

#define dis2(x) (x)*(x)

double map[21][21],maxn;

int m,n;

bool num[21];

struct node{

	double l,a,b;

}p[21];

double dis(node x,node y){

	return dis2(x.a-y.a)+dis2(x.b-y.b)+dis2(x.l-y.l);

}

void check(){

	int ln=0,cnt[21];

	double ans=0;

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

		if(num[i])

			cnt[++ln]=i;

	if(ln>m)

		return;

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

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

			ans+=map[cnt[i]][cnt[j]];

	if(ans>maxn)

		maxn=ans;

}

void solve(int t){

	if(t>n){

		check();

		return;

	}

	num[t]=true;

	solve(t+1);

	num[t]=false;

	solve(t+1);



}

int main(){

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

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

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

		memset(num,false,sizeof(num));

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

			map[i][i]=0;

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

				map[i][j]=map[j][i]=dis(p[i],p[j]);

		}

		maxn=-1;

		solve(1);

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

	}

	return 0;

}

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

}
// 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 node 

{

	double x,y,z;

}e[105],q[105];



double dis(node a, node b)

{

	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z);

}

int main()

{

	int m,n,i,j,k,pp=1,t;

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

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

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

	int a[105]={0};

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

		a[i]=1;

	double mm=0;

	do

	{

		int count=0;

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

			if(a[i]==1)

				q[count++]=e[i];

		double d=0;

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

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

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

		mm=d>mm?d:mm;

	}while(next_permutation(a,a+n));

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

}

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

}
// Slower C++ solution:
#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);

    }

}

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

}
// Slower C++ solution:
/*

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;

}

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

}
// Slower C++ solution:
#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;

}

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

}
// Slower C++ solution:
#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;

}

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

}