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<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
using namespace std;


struct edge
{
 int begin;int end;	
};

const int maxx=120;
bool vis[maxx],indfs[maxx];
vector<double>zero;
int n,m,root;
vector<vector<double> >vec;
double cost[maxx][maxx],Cost[maxx][maxx];
bool operator <(const edge a,const edge b)
{
 double ac=cost[a.begin][a.end];double bc=cost[b.begin][b.end];
 return ac>bc;//´?????´?????	
};
priority_queue<edge>que[maxx];
double minv(vector<double> a,vector<double> b)
{
 double ab=0,bsqrt=0,asqrt=0;
 for(int i=0;i<a.size();i++)
 	{ab+=a[i]*b[i];bsqrt+=b[i]*b[i];asqrt+=a[i]*a[i];}
 	
 if((bsqrt-0.0)<1e-10)return asqrt;
 return asqrt-(ab*ab/bsqrt);
}
int belongcircle[maxx];
int findbelong(int x)
{
 if(x==belongcircle[x])return x;
 	else return belongcircle[x]=findbelong(belongcircle[x]);
}

double ans,ansnow;
double min(double a,double b)
{
 if(a<b)return a;
 	else return b;
}
void combinecircle(int now,int begin)
{
 now=findbelong(now);
 if(vis[now])return ;
 vis[now]=true;
 edge e1=que[now].top();
 double coste=cost[findbelong(e1.begin)][findbelong(e1.end)];
 ansnow+=coste;
 bool finish[maxx];
 memset(finish,0,sizeof(finish));
 for(int i=0;i<=m;i++)
 	{
 	 int po=findbelong(i);
 	 if(po==now||po==begin)continue;
 	 if(finish[po])continue;
 	 finish[po]=true;
 	 cost[begin][po]=min(cost[begin][po],cost[now][po]-coste);
 	 cost[po][begin]=min(cost[po][begin],cost[po][now]);
	}
 belongcircle[now]=begin;
 combinecircle(e1.end,begin);
 return ;
}
void build();
bool findcircle(int now)
{
 if(now==root)return false; 
 now=findbelong(now);
 if(indfs[now])
 	{
 	 memset(vis,0,sizeof(vis));
 	 combinecircle(now,now);
 	 build();
 	 return true;
	}
 indfs[now]=true;
 return findcircle(que[now].top().end);
}

void build()
{
 bool finish[maxx];
 memset(finish,0,sizeof(finish));
 for(int i=0;i<m;i++)
 	{
 	 int po=findbelong(i);
 	 if(finish[po])continue;
 	 finish[po]=true;
 	 while(!que[po].empty())que[po].pop();
 	 for(int j=0;j<=m;j++)
 	 	{
 	 	 int pb=findbelong(j);
 	 	 if(po==pb)continue;
 	 	 edge en;en.begin=po;en.end=pb;
 	 	 que[po].push(en);
		}
	}
 return ;
}
bool counted[maxx];
int main()
{
 ios::sync_with_stdio(false);
 cin>>n>>m;
 for(int i=0;i<n;i++)
    zero.push_back(0.0);
 for(int i=0;i<m;i++)
 	{
	 vector<double>nowv;
	 for(int j=0;j<n;j++)
	 	{ double nv;cin>>nv;nowv.push_back(nv);}
	 vec.push_back(nowv);
	}
 vec.push_back(zero);
 for(int i=0;i<=m;i++)
 	for(int j=0;j<=m;j++)
 		{ cost[i][j]=minv(vec[i],vec[j]);}
 root=m;
 ansnow=0;
 belongcircle[root]=root;
 	 for(int i=0;i<m;i++)
 	 	{
 	 	 belongcircle[i]=i;
 	 	}
	 bool exis=false;
	 	 do
	 	 	{
	 	 	 build();
	 	 	 exis=false;
	 	 	 bool finish[maxx];
	 	 	 memset(finish,0,sizeof(finish));
	 	 	 for(int i=0;i<m;i++)
	 	 	 {  
			    int po=findbelong(i);
			    if(finish[po])continue;
	 	 	    memset(indfs,0,sizeof(indfs));
	 	 	    exis=findcircle(po);
	 	 	    finish[po]=true;
			 }
			}while(exis);
	 memset(counted,0,sizeof(counted));
	 for(int i=0;i<m;i++)
	 	{
		 int po=findbelong(i);
		 if(counted[po])continue;
		 counted[po]=true;
		 ansnow+=cost[findbelong(que[po].top().begin)][findbelong(que[po].top().end)];	
		}
 printf("%.8f\n",ansnow);
 return 0;
}