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<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<iomanip>
using namespace std;
#define eps 1e-12
#define INF 1000000
#define maxn 200005
double a[105][105];
double sum[105];
struct Edge
{
    int u,v;
    double w;
}b[10005],e[10005];
int pre[maxn],id[maxn],vis[maxn];
double in[maxn];

int dcmp(double x)
{
    if(fabs(x)<eps) return 0;
    return x<0?-1:1;
}

double Directed_MST(int root, int NV, int NE)
{
    double ret = 0;
    while(1)
    {
        for(int i=0;i<NV;i++)
            in[i]=INF;
        memset(pre,-1,sizeof(pre));
        memset(vis,-1,sizeof(vis));
        memset(id,-1,sizeof(id));
        for(int i=0;i<NE;i++)
        {
            if(e[i].u==e[i].v) continue;
            int v=e[i].v;
            if(dcmp(e[i].w-in[v])<0){
      //          ans=i;
                pre[v]=e[i].u;
                in[v]=e[i].w;
            }
        }
        for(int i=0;i<NV;i++)
        {
            if(dcmp(in[i]-INF)==0&&i!=root)
            {
                //cout<<i<<endl;
                return -1;
            }
        }
        int cnt=0;
        in[root]=0;
        for(int i=0;i<NV;i++)
        {
            ret+=in[i];
            int v=i;
            while(vis[v]!=i&&id[v]==-1&&v!=root)
            {
                vis[v]=i;
                v=pre[v];
            }
            if(v!=root&&id[v]==-1){
                for(int u=pre[v];u!=v;u=pre[u])
                {
                    id[u]=cnt;
                }
                id[v]=cnt++;
            }
        }
        if(cnt==0) break;
        for(int i=0;i<NV;i++)
            if(id[i]==-1) id[i]=cnt++;
        for(int i=0;i<NE;i++)
        {
            int v=e[i].v;
            e[i].u=id[e[i].u];
            e[i].v=id[e[i].v];
            e[i].w-=in[v];
        }
        NV = cnt;
        root = id[root];
     }
    return ret;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)    for(int j=0;j<n;j++)    scanf("%lf",a[i]+j);
    int tot=0;
    for(int i=1;i<=m;i++)             //j->i??±?
    {
        for(int j=1;j<=m;j++)
        {
            double x1=0,x2=0,x3=0;     // y=r*r*x3-2*r*x2+x1
            for(int k=0;k<n;k++)
            {
                x1+=a[i][k]*a[i][k];
                x3+=a[j][k]*a[j][k];
                x2+=a[i][k]*a[j][k];
            }
            sum[i]=x1;
            if(i==j)    continue;
            double x=x2/x3;
            double y=x*x*x3-2.0*x*x2+x1;
            e[tot].u=j;
            e[tot].v=i;
            e[tot].w=y;
            tot++;
        }
    }
    for(int i=1;i<=m;i++)
    {
        e[tot].u=0;
        e[tot].v=i;
        e[tot].w=sum[i];
        tot++;
    }
    double temp=Directed_MST(0,m+1,tot);
    printf("%.7f\n",temp);
}