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 "cstring"
#include "cstdio"
#include "cmath"
using namespace std;
const double INF = 1E10;
const double eps = 1e-8;
const int N = 110;
double d[N], g[N][N], a[N][N];
int pre[N], flag[N], mark[N];
int visit[N];
double sqr(double x){return x * x;}
double gao(int x, int y, int n)
{
	double va = 0, vb = 0, vc = 0;
	for(int i = 1; i <= n; ++ i){
		va += sqr(a[x][i]);
		vc += sqr(a[y][i]);
		vb += -2.0 * a[x][i] * a[y][i];
	}
	if(fabs(va) < eps) return INF;
	return (4.0 * va * vc - vb * vb) / (4.0 * va);
}

double ZhuLiu(int root, int n)
{
	int i, j, k;
	double res = 0;
	memset(flag, 0, sizeof(flag));
	while(1){
		for(i = 1; i <= n; ++ i){
			if(flag[i] || i == root) continue;
			pre[i] = i;
			g[i][i] = INF;
			for(j = 1; j <= n; ++ j){
				if(!flag[j] && g[j][i] < g[pre[i]][i])
					pre[i] = j;
			}
		}
		for(i = 1; i <= n; ++ i){
			if(flag[i] || i == root) continue;
			memset(mark, 0, sizeof(mark));
			mark[root] = 1;
			j = i;
			do{
				mark[j] = 1;
				j = pre[j];
			}while(!mark[j]);
			if(j == root) continue;
			i = j;
			res += g[pre[i]][i];
			for(j = pre[i]; j != i; j = pre[j]){
				flag[j] = 1;
				res += g[pre[j]][j];
			}
			for(j = 1; j <= n; ++ j){
				if(!flag[j] && g[j][i] < INF){
					g[j][i] -= g[pre[i]][i];
				}
			}
			for(j = pre[i]; j != i; j = pre[j]){
				for(k = 1; k <= n; ++ k){
					if(!flag[k]){
						g[i][k] = min(g[i][k], g[j][k]);
						if(g[k][j] < INF){
							g[k][i] = min(g[k][i], g[k][j] - g[pre[j]][j]);
						}
					}
				}
			}
			break;
		}
		if(i > n){
			for(j = 1; j <= n; ++ j){
				if(!flag[j] && j != root){
					res += g[pre[j]][j];
				}
			}
			break;
		}
	}
	return res;
}
int main(void)
{
	int n, m;
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m + 1; ++ i){
		for(int j = 1; j <= m + 1; ++ j){
			g[i][j] = INF;
		}
	}	
	for(int i = 1; i <= m; ++ i){
		g[m + 1][i] = 0;
	}
	for(int i = 1; i <= m; ++ i){
		for(int j = 1; j <= n; ++ j){
			scanf("%lf", &a[i][j]);
			g[m + 1][i] += sqr(a[i][j]);
		}
	}
	for(int i = 1; i <= m; ++ i){
		for(int j = 1; j <= m; ++ j){
			if(i == j) continue;
			g[i][j] = gao(i, j, n);
		}
	}
	printf("%.10f\n", ZhuLiu(m + 1, m + 1));
	return 0;
}