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>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N (1<<19)
#define INF 100000000
#define MOD 1000000007
#define RANK 1000000000
#define EPS 1e-10
using namespace std;
typedef long long ll;
typedef pair<long double,int> P;

int n, m;
long double v[100][100];
int saw[101];
int com[101];
bool dead[101];
vector<P> e[101];
vector<P> rev[101];
vector<P> ee[101];
P ree[101];

int dfs_liu(int v, int o){
    saw[v] = o;
    rep(i,ee[v].size()){
        P p = ee[v][i];
        if(saw[p.second] >= 0 && saw[p.second] < o) continue;
        if(saw[p.second] == o){
            com[p.second] = p.second;
            while(v != p.second){
                com[v] = p.second;
                v = ree[v].second;
            }
            return p.second;
        }
        int rec = dfs_liu(p.second,o);
        if(rec != -1) return rec;
    }
    return -1;
}

long double chu_liu(){
    long double ret = 0.0;
    memset(dead,0,sizeof(dead));
    int debug = 0;
    while(true){
        debug++;
        bool end = true;
        rep(i,n){
            ee[i].clear();
            rev[i].clear();
        }
        rep(i,n) rep(j,e[i].size()){
            if(dead[i] == true || dead[e[i][j].second] == true) continue;
            rev[e[i][j].second].push_back(P(e[i][j].first,i));
        }
        /*
        rep(i,n){
            if(dead[i])  continue;
            sort(rev[i].begin(),rev[i].end());
        }
        */
        //cout << "Ho" << endl;
        memset(saw,-1,sizeof(saw));
        memset(com,-1,sizeof(com));
        rep(i,n){
            if(dead[i]) continue;
            if(rev[i].size() == 0) continue;
            long double mi = 100.0;
            rep(j,rev[i].size()) mi = min(mi,rev[i][j].first+EPS);
            rep(j,rev[i].size()){
                if(rev[i][j].first < mi){
                    ee[rev[i][j].second].push_back(P(rev[i][j].first,i));
                    ree[i] = rev[i][j];
                    break;
                }
            }
        }
        rep(i,n){
            rep(j,ee[i].size()){
                //cout << i << " " << ee[i][j].second << " " << ee[i][j].first << endl;
            }
        }
        //cout << "o" << endl;
        int d;
        rep(i,n){
            if(dead[i]) continue;
            if(saw[i] >= 0) continue;
            d = dfs_liu(i,i);
            if(d >= 0){
                end = false;
                break;
            }
        }
        //rep(i,n) cout << saw[i] << " ";
        //cout << endl;
        //rep(i,n) cout << com[i] << " ";
        //cout << endl;
        //cout << d << endl;
        if(end) break;
        rep(i,n){
            if(dead[i]) continue;
            rep(j,e[i].size()){
                if(com[i] == d && com[e[i][j].second] == d){
                    e[i][j].first = 100.0;
                    continue;
                }
                if(com[e[i][j].second] == d){
                    e[i][j].first -= ree[e[i][j].second].first;
                    e[i][j].second = d;
                    continue;
                }
                if(com[i] == d){
                    if(i != d) e[d].push_back(e[i][j]);
                }
            }
        }
        rep(i,n){
            if(dead[i]) continue;
            if(com[i] == d){
                ret += ree[i].first;
                if(i != d) dead[i] = true;
            }
        }
    }
    rep(i,n){
        if(dead[i]) continue;
        ret += ree[i].first;
    }
    return ret;
}

int main(){
    cin >> m >> n;
    rep(i,n) rep(j,m) cin >> v[i][j];
    rep(i,n){
        long double d = 0.0;
        rep(j,m) d += v[i][j]*v[i][j];
        if(d == 0.0) continue;
        e[n].push_back(P(d,i));
        rev[i].push_back(P(d,n));
        rep(j,n){
            if(i == j) continue;
            long double ss = -10000000000.0, ee = 100000000000.0, ms, me;
            long double vs, ve;
            rep(u,200){
                ms = (ss*2+ee)/3;
                me = (ss+ee*2)/3;
                vs = 0.0; ve = 0.0;
                rep(k,m){
                    vs += pow(v[j][k]+ms*v[i][k],2);
                    ve += pow(v[j][k]+me*v[i][k],2);
                }
                if(vs > ve) ss = ms;
                else ee = me;
            }
            e[i].push_back(P(vs,j));
            rev[i].push_back(P(vs,i));
        }
    }
    n++;
    rep(i,n){
        rep(j,e[i].size()){
            //cout << i << " " << e[i][j].second << " " << e[i][j].first << endl;
        }
    }
    long double ans = chu_liu();
    printf("%.9Lf\n",ans);
}