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<stdio.h>
#include<bits/stdc++.h>
#define maxn 200005 
using namespace std;
namespace NF
{
    int N=0,S=1,T=2;
    int las[maxn],to[maxn],pre[maxn],len[maxn],dis[maxn],cnt[maxn],inc=1;
    void ins(int a,int b,int c){pre[++inc]=las[a],las[a]=inc,to[inc]=b,len[inc]=c;}
    int dfs(int u,int flow)
    {
        int v,temp,delta;
        if(u==T) return flow;
        delta=0;
        for(v=las[u];v;v=pre[v]) 
        {
            if(len[v]>0&&dis[u]==dis[to[v]]+1) 
            {
                temp=dfs(to[v],min(flow-delta,len[v]));
                len[v]-=temp,len[v^1]+=temp,delta+=temp;
                if(delta==flow||dis[S]>=N) return delta;
            }
        }
        if(dis[S]>=N) return delta;
        if(!--cnt[dis[u]]) dis[S]=N;
        cnt[++dis[u]]++;
        return delta;
    }
    int Solve()
    {
        int ret=0;
        while(dis[S]<N) ret+=dfs(1,1e9);
        return ret;
    }
    void Init()
    {
    	for(int i=1;i<=N;i++) las[i]=cnt[i]=dis[i]=0;
    	inc=1,N=0;
	}
}
int g[505][505],ans[505][505],vis[505][505],val[505][505],ed[505][505],nw[505],n,m;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) scanf("%d",&g[i][j]);
	for(int cc=1;cc<=m;cc++)
	{
		NF::Init(); NF::N=2*n+2;
		memset(ed,0,sizeof(ed));
		for(int i=1;i<=n;i++)
		{
			fill(nw+1,nw+n+1,0);
			NF::ins(1,i+2,1),NF::ins(i+2,1,0);
			NF::ins(i+n+2,2,1),NF::ins(2,i+n+2,0);
			for(int j=1;j<=m;j++)
			{
				int id=(g[i][j]-1)/m+1;
				if(!vis[i][j]&&!nw[id])
				{
					NF::ins(i+2,id+n+2,1);
					ed[i][id]=NF::inc,val[i][id]=j;
					NF::ins(id+n+2,i+2,0);
				}
			}
		}
		NF::Solve();
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				if(ed[i][j]&&!NF::len[ed[i][j]])
				{
					ans[cc][i]=g[i][val[i][j]];
					vis[i][val[i][j]]=1;
					break;
				}
	}
	for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%d ",ans[j][i]);
	for(int i=1;i<=m;i++) sort(ans[i]+1,ans[i]+n+1);
	for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=m;j++) printf("%d ",ans[j][i]);
	return 0;
}