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:
//Love and Freedom.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#define ll long long
#define inf 20021225
#define N 410
#define M 40001
using namespace std;
int read()
{
	int s=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return f*s;
}
struct edge{int to,lt,f;}e[M];
int in[N],cnt,s,t,n,m; // clear!
void add(int x,int y,int f)
{
	e[++cnt].to=y; e[cnt].lt=in[x]; in[x]=cnt; e[cnt].f=f;
	e[++cnt].to=x; e[cnt].lt=in[y]; in[y]=cnt; e[cnt].f=0;
}
queue<int> que; int dep[N];
bool bfs()
{
	//printf("GG");
	while(!que.empty())	que.pop();
	memset(dep,0,sizeof(dep)); que.push(s); dep[s]=1;
	while(!que.empty())
	{
		int x=que.front(); que.pop();
		for(int i=in[x];i;i=e[i].lt)	if(!dep[e[i].to] && e[i].f)
		{
			dep[e[i].to]=dep[x]+1,que.push(e[i].to);
			if(e[i].to==t)	return 1;
		}
	}
	return 0;
}
int dfs(int x,int flow)
{
	if(x==t)	return flow;
	int cur=flow;
	for(int i=in[x];i;i=e[i].lt)
	{
		int y=e[i].to; if(dep[y]==dep[x]+1 && e[i].f)
		{
			int tmp=dfs(y,min(cur,e[i].f));// printf("GG");
			cur-=tmp; e[i].f-=tmp; e[i^1].f+=tmp;
			if(!cur)	return flow;
		}
	}
	dep[x]=-1; return flow-cur;
}
vector<int> val[N][N]; int sz[N][N];
void link()
{
	cnt=1; s=N-3; t=s+1;
	memset(in,0,sizeof(in));
	for(int i=1;i<=n;i++)
	{
		add(s,i,1);
		for(int j=1;j<=n;j++)
			if(sz[i][j]<val[i][j].size())	add(i,n+j,1);
	}
	for(int i=1;i<=n;i++)	add(n+i,t,1);
}
int r[N],b[N][N],a[N][N];
void dinic()
{
	//printf("QAQ");
	while(bfs())	dfs(s,inf);
	//printf("QwQ");
	for(int i=1;i<=n;i++)
		for(int j=in[i];j;j=e[j].lt)
		{
			if(e[j].to!=s && e[j^1].f)
			{
				r[i]=e[j].to-n;// printf("%d %d\n",i,r[i]);
				break;
			}
		}
	//printf("QAQ");
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=n;i++)	for(int j=1;j<=m;j++)
	{
		a[i][j]=read(); int id=(a[i][j]-1)/m+1; val[i][id].push_back(a[i][j]);
		//printf("%d %d\n",i,id);
	}
	//printf("OVO");
	for(int i=1;i<=m;i++)
	{
		link(); dinic();// printf("GG");
		for(int j=1;j<=n;j++)	b[j][i]=val[j][r[j]][sz[j][r[j]]++];
		//printf("QAQ");
	}
	for(int i=1;i<=n;i++,printf("\n"))	for(int j=1;j<=m;j++)
		printf("%d ",b[i][j]),a[j][i]=b[i][j];
	for(int i=1;i<=m;i++)	sort(a[i]+1,a[i]+n+1);
	for(int i=1;i<=n;i++,printf("\n"))	for(int j=1;j<=m;j++)
		printf("%d ",a[j][i]);
	return 0;
}