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 fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define fee(i,u) for(int&i=cur[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=110;
int n,m,a[N][N],vis[N*N],ans1[N][N],ans2[N][N];
int head[N<<1],tot,vs,vt;
struct edge{int v,f,next;}e[100010];

inline void add(int u,int v)
{
	e[++tot]=edge{v,1,head[u]};head[u]=tot;
	e[++tot]=edge{u,0,head[v]};head[v]=tot;
}

namespace flow{
int d[N<<1],cur[N<<1];
bool bfs(int vs)
{
	memset(d,-1,sizeof d);
	memset(cur,0,sizeof cur);
	d[vs]=0;cur[vs]=head[vs];
	static queue<int>q;while(!q.empty())q.pop();
	q.push(vs);
	while(!q.empty()){
		int u=q.front();q.pop();
		fe(i,u){
			int v=e[i].v,f=e[i].f;
			if(!~d[v]&&f){
				d[v]=d[u]+1;cur[v]=head[v];
				if(v==vt)return 1;
				q.push(v);
			}
		}
	}
	return 0;
}
int dfs(int u,int a)
{
	if(u==vt||!a)return a;
	int ans=0;
	fee(i,u){
		int v=e[i].v,f=e[i].f;
		if(f&&d[v]==d[u]+1){
			f=dfs(v,min(f,a));
			if(!f)continue;
			e[i].f-=f;e[i^1].f+=f;
			a-=f;ans+=f;if(!a)break;
		}
	}
	return ans;
}
inline void gao()
{
	while(bfs(vs))
		dfs(vs,1e9);
}

}

inline void gao(int id)
{
	memset(head,0,sizeof head);
	vs=0;vt=n+n+1;tot=1;
	fo(i,1,n)fo(j,1,m)if(!vis[a[i][j]])add(i,n+(a[i][j]+m-1)/m);
	fo(i,1,n)add(vs,i),add(i+n,vt);
	flow::gao();
	fo(u,1,n){
		int hh=0;
		fe(i,u){int v=e[i].v;if(v>n&&!e[i].f)hh=v-n;}
		fo(i,1,m)if(!vis[a[u][i]]&&(a[u][i]+m-1)/m==hh){
			vis[a[u][i]]=1;ans1[u][id]=a[u][i];break;
		}
	}
}

int main()
{
	n=rd();m=rd();
	fo(i,1,n)fo(j,1,m)a[i][j]=rd();
	fo(i,1,m)gao(i);
	fo(i,1,n){
		fo(j,1,m)printf("%d ",ans1[i][j]);el;
	}
	fo(i,1,n)fo(j,1,m)ans2[(ans1[i][j]+m-1)/m][j]=ans1[i][j];
	fo(i,1,n){
		fo(j,1,m)printf("%d ",ans2[i][j]);el;
	}
	return 0;
}