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:
/*Lucky_Glass*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100,inf=(1<<29);

int Rr,Cc,Ps,Pt,Emat[N+3][N+3],Edep[N*3],Eans[N+3][N+3];
bool Bb[N+3][N+3];
vector<int> Vec[N+3];

struct GGRAPH{
	struct GNODE{
		int to,cap,Vx,Vy;
		GNODE *nxt,*rev;
	}Gnod[(N*N+N*2)*3];
	GNODE *Gtop[N*3],*Gcnt;
	void Init(int Nn){
		Gcnt=Gnod;
		fill(Gtop,Gtop+1+Nn,Gcnt);
	}
	void AddEdge(int u,int v,int ca1,int ca2,int Vx,int Vy){
		GNODE *p=++Gcnt,*q=++Gcnt;
		*p=(GNODE){v,ca1,Vx,Vy,Gtop[u],q};Gtop[u]=p;
		*q=(GNODE){u,ca2,Vx,Vy,Gtop[v],p};Gtop[v]=q;
	}
}Gflw;

GGRAPH::GNODE *Cop[N*3];

int Aug(int u,int flwin){
	if(u==Pt) return flwin;
	int flwout=0;
	for(auto &it=Cop[u];it;it=it->nxt){
		int v=it->to;
		if(!it->cap || Edep[v]!=Edep[u]+1) continue;
		int flwv=min(flwin-flwout,it->cap);
		flwv=Aug(v,flwv);
		flwout+=flwv;
		it->cap-=flwv;
		it->rev->cap+=flwv;
		if(flwout==flwin) break;
	}
	return flwout;
}
bool BFS(){
	for(int i=1;i<=Rr*2+2;i++)
		Cop[i]=Gflw.Gtop[i],Edep[i]=inf;
	queue<int> que;
	Edep[Ps]=0;
	que.push(Ps);
	while(!que.empty()){
		int u=que.front();que.pop();
		for(auto it=Cop[u];it;it=it->nxt){
			int v=it->to;
			if(!it->cap || Edep[v]!=inf) continue;
			Edep[v]=Edep[u]+1;
			if(v==Pt) return true;
			que.push(v);
		}
	}
	return false;
}
int Dinic(){
	int mxflw=0;
	while(BFS()) mxflw+=Aug(Ps,inf);
	return mxflw;
}
int main(){
	scanf("%d%d",&Rr,&Cc);
	Ps=2*Rr+1;Pt=2*Rr+2;
	for(int i=1;i<=Rr;i++)
		for(int j=1;j<=Cc;j++)
			scanf("%d",&Emat[i][j]);
	for(int i=1;i<=Cc;i++){
		Gflw.Init(2*Rr+2);
		int Vtot=0;
		for(int j=1;j<=Rr;j++)
			for(int k=1;k<=Cc;k++)
				if(!Bb[j][k]){
					Gflw.AddEdge(j,(Emat[j][k]-1)/Cc+1+Rr,1,0,j,k);
					Vtot+=2;
				}
		for(int j=1;j<=Rr;j++) Gflw.AddEdge(Ps,j,1,0,0,0);
		for(int j=1;j<=Rr;j++) Gflw.AddEdge(j+Rr,Pt,1,0,0,0);
		int Rs=Dinic();
		for(int j=1;j<=Vtot;j+=2){
			auto it=Gflw.Gnod[j];
			if(it.cap==0){
				Eans[it.Vx][i]=Emat[it.Vx][it.Vy];
				Bb[it.Vx][it.Vy]=true;
			}
		}
	}
	for(int i=1;i<=Rr;i++)
		for(int j=1;j<=Cc;j++){
			printf("%d",Eans[i][j]);
			Vec[j].push_back(Eans[i][j]);
			if(j==Cc) printf("\n");
			else printf(" ");
		}
	for(int i=1;i<=Cc;i++){
		sort(Vec[i].begin(),Vec[i].end());
		for(int j=1;j<=Rr;j++)
			Eans[j][i]=Vec[i][j-1];
	}
	for(int i=1;i<=Rr;i++)
		for(int j=1;j<=Cc;j++){
			printf("%d",Eans[i][j]);
			if(j==Cc) printf("\n");
			else printf(" ");
		}
	return 0;
}