#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<functional>
#include<cstdlib>
#include<ctime>
#include<cassert>
#include<iomanip>
#include<string>
#include<cstring>
#include<cctype>
#include<cmath>
#include<list>
#include<iterator>
using namespace std;
typedef long long ll;
#define FRN(i,a,b) for(ll i=a;i<(ll)b;i++)
#define pb push_back
#define mp make_pair
#define INF 100000
#define MOD 1000000009
typedef vector<ll> vi;
typedef vector<vector<ll> > vvi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<ll,ll> pi;
typedef map<ll,ll> mii;
typedef map<string,ll> msi;
typedef map<ll,string> mis;
typedef vector<pair<int,int> > vp;
typedef set<ll> si;
typedef set<string> ss;
using namespace std;
#define EPS 1e-9
main(){
int n,m;
cin>>n>>m;
double a[n][m];
for(ll i=0;i<n;i++)for(ll j=0;j<m;j++)cin>>a[i][j];
double det = 1;
for (int i=0;i<n;++i) {
int k = i;
for (int j=i+1;j<n;++j)
if (abs(a[j][i])>abs(a[k][i]))
k=j;
if (abs(a[k][i])<EPS) {
det = 0;
break;
}
for(int s=i;s<m;s++){
double tmp=a[i][s];
a[i][s]=a[k][s];
a[k][s]=tmp;
}
if(i!=k)
det =-det;
det*= a[i][i];
for (int j=n-1;j>=i;--j)
a[i][j]/= a[i][i];
for (int j=0;j<n;++j)
if (j!=i&&abs(a[j][i])>EPS)
for (int k=n-1;k>=i;--k)
a[j][k]-= a[i][k]*a[j][i];
for(ll i=0;i<n;i++){
for(ll j=0;j<m;j++)cout<<" "<<a[i][j];
cout<<endl;
}
cout<<endl;
}
cout<<det;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHZlY3Rvcj4KI2luY2x1ZGU8bWFwPgojaW5jbHVkZTxzZXQ+CiNpbmNsdWRlPGFsZ29yaXRobT4KI2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxmdW5jdGlvbmFsPgojaW5jbHVkZTxjc3RkbGliPgojaW5jbHVkZTxjdG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