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 <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
const int M = 10000 + 10;
struct edge
{
    int u, v;
    double cost;
    edge() {}
    edge(int u, int v, double c): u(u), v(v), cost(c) {}
} e[M];
int pre[N], hash1[N], vis[N];
double In[N];
double Directed_MST(int root, int n, int m)
{
    double ret = 0;
    while(true)
    {
        for(int i = 0; i < n; i++)
            In[i] = INT_MAX;
        for(int i = 0; i < m; i++) //找最小入?
        {
            int u = e[i].u;
            int v = e[i].v;
            if(e[i].cost < In[v] && u != v)
            {
                pre[v] = u;
                In[v] = e[i].cost;
            }
        }
        for(int i = 0; i < n; i++)
        {
            if(i == root)
                continue;
            if(In[i] == INT_MAX)
                return -1;
        }
        int cntnode = 0;
        memset(hash1, -1, sizeof(hash1));
        memset(vis, -1, sizeof(vis));
        In[root] = 0;
        for(int i = 0; i < n; i++) //找?
        {
            ret += In[i];
            int v = i;
            while(vis[v] != i && hash1[v] == -1 && v != root)
            {
                vis[v] = i;
                v = pre[v];
            }
            if(v != root && hash1[v] == -1)
            {
                for(int u = pre[v]; u != v; u = pre[u])
                    hash1[u] = cntnode;
                hash1[v] = cntnode++;
            }
        }
        if(cntnode == 0)
            break;
        for(int i = 0; i < n; i++)
            if(hash1[i] == -1)
                hash1[i] = cntnode++;
        for(int i = 0; i < m; i++) //重??
        {
            int v = e[i].v;
            e[i].u = hash1[e[i].u];
            e[i].v = hash1[e[i].v];
            if(e[i].u != e[i].v)
                e[i].cost -= In[v];
        }
        n = cntnode;
        root = hash1[root];
    }
    return ret;
}
int n, m;
const int MAXV = 100 + 10;
double vc[MAXV][MAXV];
double A, B, C;
inline double calCost(double r)
{
    return A - r * B + r * r * C;
}
const double EPS = 1e-10;
inline int sgn(double x) {return x < -EPS ? -1 : x > EPS ? 1 : 0;}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
//	freopen("in.txt", "w", stdout);
#endif
    scanf("%d%d", &m, &n);
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < m; ++j)
            scanf("%lf", &vc[i][j]);
    int tot = 0;
    for(int i = 1; i <= n; ++i)
    {
        double val = 0.0;
        for(int j = 0; j < m; ++j)
            val += vc[i][j] * vc[i][j];
        e[tot++] = edge(0, i, val);
    }
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
        {
            if(i == j) continue;
            A = 0, B = 0, C = 0;
            for(int k = 0; k < m; ++k)
            {
                A += vc[i][k] * vc[i][k];
                B += 2.0 * vc[i][k] * vc[j][k];
                C += vc[j][k] * vc[j][k];
            }
            double l = -1e8, r = 1e8, ll, rr;
            for(int k = 0; k < 100; ++k)
            {
                ll = (l + l + r) / 3.0;
                rr = (l + r + r) / 3.0;
                if(sgn(calCost(ll) - calCost(rr)) >= 0) l = ll;
                else r = rr;
            }
            e[tot++] = edge(j, i, calCost(l));
        }
    double ans = Directed_MST(0, n + 1, tot);
    printf("%.10f\n", ans);
    return 0;
}