Problem: We have a grid with N rows and M columns of squares. Each integer from 1 to NM is written in this grid once. The number written in the square at the i-th row from the top and the j-th column from the left is A_{ij}.

You need to rearrange these numbers as follows:

1. First, for each of the N rows, rearrange the numbers written in it as you like.
2. Second, for each of the M columns, rearrange the numbers written in it as you like.
3. Finally, for each of the N rows, rearrange the numbers written in it as you like.



After rearranging the numbers, you want the number written in the square at the i-th row from the top and the j-th column from the left to be M\times (i-1)+j. Construct one such way to rearrange the numbers. The constraints guarantee that it is always possible to achieve the objective.

Constraints

* 1 \leq N,M \leq 100
* 1 \leq A_{ij} \leq NM
* A_{ij} are distinct.

Input

Input is given from Standard Input in the following format:


N M
A_{11} A_{12} ... A_{1M}
:
A_{N1} A_{N2} ... A_{NM}


Output

Print one way to rearrange the numbers in the following format:


B_{11} B_{12} ... B_{1M}
:
B_{N1} B_{N2} ... B_{NM}
C_{11} C_{12} ... C_{1M}
:
C_{N1} C_{N2} ... C_{NM}


Here B_{ij} is the number written in the square at the i-th row from the top and the j-th column from the left after Step 1, and C_{ij} is the number written in that square after Step 2.

Examples

Input

3 2
2 6
4 3
1 5


Output

2 6
4 3
5 1
2 1
4 3
5 6


Input

3 4
1 4 7 10
2 5 8 11
3 6 9 12


Output

1 4 7 10
5 8 11 2
9 12 3 6
1 4 3 2
5 8 7 6
9 12 11 10

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=222,maxm=22222;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,m,a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],tmp[maxn];
int s,t,q[maxn],h,r,dis[maxn],el,head[maxn],cur[maxn],to[maxm],nxt[maxm],w[maxm];
bool use[maxm];
inline void add(int u,int v,int w_){
	to[++el]=v;nxt[el]=head[u];head[u]=el;w[el]=w_;
	to[++el]=u;nxt[el]=head[v];head[v]=el;w[el]=0;
}
bool bfs(){
	MEM(dis,-1);
	q[h=r=1]=s;
	dis[s]=0;
	while(h<=r){
		int u=q[h++];
		for(int i=head[u];i;i=nxt[i]) if(w[i]){
			int v=to[i];
			if(dis[v]==-1) dis[v]=dis[u]+1,q[++r]=v;
		}
	}
	return ~dis[t];
}
int dfs(int u,int minres){
	if(u==t || !minres) return minres;
	int f,rtf=0;
	for(int &i=cur[u];i;i=nxt[i]){
		int v=to[i];
		if(dis[v]==dis[u]+1 && (f=dfs(v,min(minres,w[i])))){
			minres-=f;rtf+=f;
			w[i]-=f;w[i^1]+=f;
			if(!minres) break;
		}
	}
	return rtf;
}
int main(){
	n=read();m=read();
	FOR(i,1,n) FOR(j,1,m) a[i][j]=read();
	s=2*n+1;t=2*n+2;
	FOR(i,1,m){
		FOR(i,1,2*n+2) head[i]=0;
		FOR(i,1,el) to[i]=nxt[i]=w[i]=0;
		el=1;
		FOR(i,1,n) add(s,i,1),add(i+n,t,1);
		FOR(i,1,n) FOR(j,1,m) if(!use[a[i][j]]) add(i,(a[i][j]+m-1)/m+n,1);
		int f=0;
		while(bfs()){
			FOR(i,1,2*n+2) cur[i]=head[i];
			f+=dfs(s,1e9);
		}
		assert(f==n);
		FOR(j,1,n) for(int e=head[j];e;e=nxt[e]) if(!w[e]){
			int tp=to[e]-n;
			FOR(k,1,m) if((a[j][k]+m-1)/m==tp && !use[a[j][k]]){
				use[b[j][i]=a[j][k]]=true;break;
			}
		}
	}
	FOR(i,1,n){
		FOR(j,1,m) printf("%d ",b[i][j]);
		puts("");
	}
	FOR(j,1,m){
		FOR(i,1,n) tmp[i]=b[i][j];
		sort(tmp+1,tmp+n+1);
		FOR(i,1,n) c[i][j]=tmp[i];
	}
	FOR(i,1,n){
		FOR(j,1,m) printf("%d ",c[i][j]);
		puts("");
	}
}
// wtf flow