Problem: You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors. Since the result may become very large, you are thinking of compressing it. Fortunately you already have a good compression method for vectors with small absolute values, all you have to do is to preprocess the vectors and make them small.

You can record the set of vectors in any order you like. Let's assume you process them in the order v_1, v_2,..., v_M. Each vector v_i is recorded either as is, or as a difference vector. When it is recorded as a difference, you can arbitrarily pick up an already chosen vector v_j (j<i) and a real value r. Then the actual vector value recorded is (v_i - r v_j). The values of r and j do not affect the compression ratio so much, so you don't have to care about them.

Given a set of vectors, your task is to write a program that calculates the minimum sum of the squared length of the recorded vectors.



Input

The input is like the following style.

N M
v_{1,1} v_{1,2} ... v_{1,N}
...
v_{M,1} v_{M,2} ... v_{M,N}


The first line contains two integers N and M (1 \leq N, M \leq 100), where N is the dimension of each vector, and M is the number of the vectors. Each of the following M lines contains N floating point values v_{i,j} (-1.0 \leq v_{i,j} \leq 1.0) which represents the j-th element value of the i-th vector.

Output

Output the minimum sum of the squared length of the recorded vectors. The output should not contain an absolute error greater than 10^{-6}.

Examples

Input

2 3
1.0 1.0
-1.0 0.0
0.5 0.5


Output

1.0


Input

1 1
1.0


Output

1.0


Input

4 3
1.0 1.0 0.0 0.0
-1.0 0.0 -1.0 0.0
0.5 0.5 0.5 0.5


Output

3.0

Solution (in CPP):

Solution:
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
double c[110][110];
double g[210][210];
int rev[210];
int v[210];
int w[210];
int u[210];
double eps=1e-9;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		for(int j=0;j<a;j++){
			scanf("%lf",&c[i][j]);
		}
	}
	for(int i=0;i<210;i++)
		for(int j=0;j<210;j++)
			g[i][j]=999999999;
	int s=b;
	for(int i=0;i<b;i++){
		double dist=0;
		for(int j=0;j<a;j++)dist+=c[i][j]*c[i][j];
		g[s][i]=dist;
		for(int j=0;j<b;j++){
			if(i==j)continue;
			double L=-99999999;
			double R=99999999;
			for(int k=0;k<100;k++){
				double m1=(L*2+R)/3;
				double m2=(L+R*2)/3;
				double d1=0;
				double d2=0;
				for(int l=0;l<a;l++){
					d1+=(c[i][l]*m1-c[j][l])*(c[i][l]*m1-c[j][l]);
					d2+=(c[i][l]*m2-c[j][l])*(c[i][l]*m2-c[j][l]);
				}
				g[i][j]=min(g[i][j],min(d1,d2));
				if(d1<d2)R=m2;
				else L=m1;
			}
		}
	}

	double ret=0;
	int sz=b+1;
	int rt=b;
//		for(int i=0;i<sz;i++){
//		for(int j=0;j<sz;j++)printf("%f ",g[i][j]);
//		printf("\n");
//	}
	while(1){
		for(int i=0;i<sz;i++){
			if(v[i])continue;
			if(rt==i)continue;
			rev[i]=-1;
	//		printf("%d\n",i);
			for(int j=0;j<sz;j++){
				if(v[j])continue;
				if(i==j)continue;
				if(!~rev[i]||g[rev[i]][i]>g[j][i])rev[i]=j;
			}
			
			if(!u[i])ret+=g[rev[i]][i];
			u[i]=1;
		}
		//printf("%d\n",sz);
	//	for(int i=0;i<sz;i++)printf("%d ",rev[i]);printf("\n");
	//	if(sz>6)return 0;
		for(int i=0;i<210;i++)w[i]=0;
		int cnt=0;
		int SZ=sz;
		for(int i=0;i<SZ;i++){
			if(v[i])continue;
			if(w[i])continue;
			if(i==rt)continue;
			int at=i;
			while(1){
				if(w[at]==2){
					cnt++;
					vector<int>vs;
					int a2=at;
					if(w[rt]==2)rt=sz;
					while(1){
						if(w[a2]==1)break;
						vs.push_back(a2);
						w[a2]=1;v[a2]=1;
						a2=rev[a2];
					}
				//	printf("{");
					for(int j=0;j<vs.size();j++){
				//		printf("%d,",vs[j]);
						for(int k=0;k<sz;k++){
							if(g[vs[j]][k]<999999)g[sz][k]=min(g[sz][k],g[vs[j]][k]);
							if(g[k][vs[j]]<999999)g[k][sz]=min(g[k][sz],g[k][vs[j]]-g[rev[vs[j]]][vs[j]]);
						}
					}//printf("}\n");
					sz++;
					break;
				}
				if(w[at]==1)break;
				if(at==rt)break;
				w[at]=2;
				at=rev[at];
			}
			at=i;
			while(1){
				if(w[at]==1)break;
				if(at==rt)break;
				w[at]=1;
				at=rev[at];
			}
		}
		if(!cnt)break;
	}
	printf("%f\n",ret);
}