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 <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

const int N = 111;
const double eps = 1e-10;
int n, m, pos[N];
double v[N][N], val[N], dist[N][N];

double get_r(int i, int j)
{
    double up = 0.0;
    double down = 0.0;
    for (int k = 1; k <= n; ++k) {
        up += v[j][k] * v[i][k];
        down += v[j][k] * v[j][k];
    }
    if (fabs(down) < eps) return 0;
    return up / down;
}

bool cmp(const int &x, const int &y) {
    return y < x;
}

namespace Chuliu{
    int n, used[N], pass[N], eg[N], more, que[N];
    double g[N][N];
    void combine(int id, double &sum) {
        int tot = 0, from, i, j, k;
        for ( ; id != 0 && !pass[id]; id = eg[id])
            que[tot++] = id, pass[id] = 1;
        for (from = 0; from < tot && que[from] != id; from++);
        if (from == tot) return;

        more = 1;
        for (i = from; i < tot; i++) {
            sum += g[eg[que[i]]][que[i]];
            if (i == from) continue;
            for (j = used[que[i]] = 1; j <= n; j++)
                if (!used[j])
                    if (g[que[i]][j] < g[id][j])
                        g[id][j] = g[que[i]][j];
        }
        for (i = 1; i <= n; i++)
            if (!used[i] && i != id) {
                for (j = from; j < tot; j++) {
                    k = que[j];
                    if (g[i][id] > g[i][k] - g[eg[k]][k])
                        g[i][id] = g[i][k] - g[eg[k]][k];
                }
            }
    }
    void clear(int V) {
        n = V;
        for (int i = 1; i <= n; ++i)
            for (int j = 1; j <= n; ++j)
                g[i][j] = dist[i][j];
        for(int i = 1; i <= n; ++i)
            g[i][i] = 0x3f3f3f3f;
    }
    double solve(int root) {
        int i, j, k;
        double sum = 0.0;
        memset(used, 0, sizeof(int) * (n + 1));
        for (more = 1; more; ) {
            more = 0;
            memset(eg, 0, sizeof(int) * (n + 1));
            for (i = 1; i <= n; i++)
                if (!used[i] && i != root) {
                    for (j = 1, k = 0; j <= n; j++)
                        if (!used[j] && i != j)
                            if (k == 0 || g[j][i] < g[k][i]) k = j;
                    eg[i] = k;
                }
            memset(pass, 0, sizeof(int) * (n + 1));
            for (i = 1; i <= n; i++)
                if (!used[i] && !pass[i] && i != root)
                    combine(i, sum);
        }
        for (i = 1; i <= n; ++i)
            if (!used[i] && i != root)
                sum += g[eg[i]][i];
        return sum;
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;
    double max_val = 0;
    for (int i = 1; i <= m; ++i) {
        val[i] = 0.0;
        for (int j = 1; j <= n; ++j) {
            cin >> v[i][j];
            val[i] += v[i][j] * v[i][j];
        }
    }
    
    for (int i = 1; i <= m; ++i) {
        for (int j = 1; j <= m; ++j) {
            dist[j][i] = 0.0;
            double r = get_r(i, j);
            for (int k = 1; k <= n; ++k)
                dist[j][i] += (v[i][k] - r * v[j][k]) * (v[i][k] - r * v[j][k]);
            max_val += dist[j][i];
        }
    }
    max_val *= 2.0;
    for (int i = 1; i <= m; ++i)
        dist[i][m + 1] = dist[m + 1][i] = max_val + val[i];

    Chuliu::clear(m + 1);
    double ans = Chuliu::solve(m + 1) - max_val;

    cout << setiosflags(ios::fixed) << setprecision(10) << ans << endl;
    return 0;
}