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>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=105;
struct edge{
	int to,next,f;
}e[N*N*2];
int head[N*2],tot,S,T;
int n,m,a[N][N],q[N*2],dis[N*2];
vector<int> vec[N][N];
void add(int x,int y,int f){
	e[++tot]=(edge){y,head[x],f};
	head[x]=tot;
	e[++tot]=(edge){x,head[y],0};
	head[y]=tot;
}
bool bfs(){
	For(i,1,T) dis[i]=-1;
	int h=0,t=1;
	q[1]=S; dis[S]=0;
	while (h!=t){
		int x=q[++h];
		for (int i=head[x];i;i=e[i].next)
			if (dis[e[i].to]==-1&&e[i].f){
				dis[e[i].to]=dis[x]+1;
				q[++t]=e[i].to;
				if (e[i].to==T) return 1;
			}
	}
	return 0;
}
int dfs(int x,int flow){
	if (x==T) return flow;
	int k,rest=flow;
	for (int i=head[x];i&&rest;i=e[i].next)
		if (dis[e[i].to]==dis[x]+1&&e[i].f){
			k=dfs(e[i].to,min(rest,e[i].f));
			e[i].f-=k; e[i^1].f+=k; rest-=k;
		}
	if (rest) dis[x]=-1;
	return flow-rest;
}
int main(){
	scanf("%d%d",&n,&m);
	For(i,1,n) For(j,1,m){
		int x;
		scanf("%d",&x);
		int be=(x-1)/m+1;
		vec[i][be].PB(x);
	}
	For(i,1,m){
		memset(head,0,sizeof(head));
		tot=1; S=2*n+1; T=2*n+2;
		For(j,1,n){
			add(S,j,1);
			add(j+n,T,1);
			For(k,1,n)
				if (vec[j][k].size())
					add(j,k+n,1);
		}
		for (;bfs();dfs(S,1<<30));
		For(j,1,n)
			for (int k=head[j];k;k=e[k].next)
				if (e[k].f==0&&e[k].to!=S){
					int op=e[k].to-n;
					a[j][i]=vec[j][op].back();
					vec[j][op].pop_back();
				}
	}
	For(i,1,n) For(j,1,m)
		printf("%d%c",a[i][j],j==m?'\n':' ');
	For(i,1,n) For(j,1,m) For(k,i+1,n)
		if (a[i][j]>a[k][j]) swap(a[i][j],a[k][j]);
	For(i,1,n) For(j,1,m)
		printf("%d%c",a[i][j],j==m?'\n':' ');
}