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

}

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

}

// Faster C++ solution for the same problem (measured speedup: 4.811584577982202x):
#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 <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.825067018472551x):
#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 <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.854384534500497x):
#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 <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.855361251007269x):
#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<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.838669344838721x):
#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 <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.8295596137659995x):
#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<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.8376946499291x):
#include<cmath>

#include<cstdio>

#include<cstring>

#include<cstdlib>

#include<algorithm>

using namespace std;

const double eps = 1e-10;

const int N=25;



struct point {

    double x,y,z;

}pt[N];

int n,m;

double dis[N][N];



double dist(point p1,point p2) {

    return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z);

}



double ret;

int ans[N];

void dfs(int idx,int k,double sum) {

    if(k+(n-idx)+2<m) return;

    if(k==m) {

        ret=max(ret,sum);

        return;

    }



    dfs(idx+1,k,sum);

    double tmp=0;

    for(int i=0;i<k;i++) tmp+=dis[ans[i]][idx];

    ans[k]=idx;

    dfs(idx+1,k+1,sum+tmp);

}



int main()

{

    int i,j,t,cas=0;

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

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

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

        }

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

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

                dis[i][j]=dist(pt[i],pt[j]);

            }

        }



        ret=0.0;

        dfs(1,0,0);



        printf("%.10f\n",ret);

    }

    return 0;

}



/*

20 10

0 0 0

1 1 1

2 2 2

3 3 3

4 4 4

5 5 5

6 6 6

7 7 7

8 8 8

9 9 9

10 10 10

11 11 11

12 12 12

13 13 13

14 14 14

15 15 15

16 16 16

17 17 17

18 18 18

19 19 19

*/