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<stack>
#include<cstdio>
#include<vector>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int V_MAX=101;
const double INF=1e77;

int ord[V_MAX],low[V_MAX];
void dfs(int u,int &c,stack<int> &S,bool *inS,const vector<int> *G,int &scc_id,int *scc){
	ord[u]=low[u]=c++;
	S.push(u);
	inS[u]=true;

	rep(i,G[u].size()){
		int v=G[u][i];
		if(ord[v]==-1){
			dfs(v,c,S,inS,G,scc_id,scc);
			low[u]=min(low[u],low[v]);
		}
		else if(inS[v]){
			low[u]=min(low[u],ord[v]);
		}
	}

	if(ord[u]==low[u]){
		int v;
		do{
			v=S.top(); S.pop();
			inS[v]=false;
			scc[v]=scc_id;
		}while(v!=u);
		scc_id++;
	}
}

int SCC(int n,const vector<int> *G,int *scc){
	static bool inS[V_MAX];
	rep(u,n){
		ord[u]=-1;
		inS[u]=false;
	}
	stack<int> S;
	int c=0,n_scc=0;
	rep(u,n) if(ord[u]==-1) dfs(u,c,S,inS,G,n_scc,scc);
	return n_scc;
}

template<class T>
struct edge{
	int v;
	T cost;
};

template<class T>
T minimum_arborescence(int n,const vector< edge<T> > *G_in,int root){
	static vector< edge<T> > buf[V_MAX],buf2[V_MAX],*G=buf,*G2=buf2;
	rep(u,n) G[u].clear();
	rep(u,n) rep(i,G_in[u].size()) {
		const edge<T> &e=G_in[u][i];
		if(u!=e.v) G[u].push_back(e);
	}

	T ans=0;
	while(1){
		static int from[V_MAX];
		static T mini[V_MAX];
		rep(u,n) from[u]=-1;
		rep(u,n) rep(i,G[u].size()) {
			const edge<T> &e=G[u][i];
			if(from[e.v]==-1 || mini[e.v]>e.cost){
				from[e.v]=u;
				mini[e.v]=e.cost;
			}
		}

		rep(v,n) if(v!=root) {
			ans+=mini[v];
			if(from[v]==-1) return INF;
		}

		static vector<int> H[V_MAX];
		rep(v,n) H[v].clear();
		rep(v,n) if(v!=root) H[from[v]].push_back(v);

		static int scc[V_MAX];
		int N=SCC(n,H,scc);
		if(n==N) return ans;

		rep(i,N) G2[i].clear();
		rep(u,n) rep(i,G[u].size()) {
			const edge<T> &e=G[u][i];
			if(scc[u]!=scc[e.v]){
				G2[scc[u]].push_back((edge<T>){scc[e.v],e.cost-mini[e.v]});
			}
		}
		swap(G,G2);
		n=N;
		root=scc[root];
	}
}

int main(){
	int n,m; scanf("%d%d",&m,&n);
	double vec[101][100];
	rep(i,n) rep(j,m) scanf("%lf",vec[i]+j);
	rep(j,m) vec[n][j]=0;

	vector< edge<double> > G[V_MAX];
	rep(v,n){
		double cost=0;
		rep(k,m) cost+=vec[v][k]*vec[v][k];
		G[n].push_back((edge<double>){v,cost});
	}
	rep(u,n) rep(v,n+1) {
		double r1=0,r2=0;
		rep(k,m){
			r1+=vec[u][k]*vec[v][k];
			r2+=vec[u][k]*vec[u][k];
		}
		if(r2==0) continue;
		double r=r1/r2;

		double cost=0;
		rep(k,m) cost+=(vec[v][k]-r*vec[u][k])*(vec[v][k]-r*vec[u][k]);
		G[u].push_back((edge<double>){v,cost});
	}

	printf("%.9f",minimum_arborescence(n+1,G,n));

	return 0;
}