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>
using namespace std;
#define inf 2123333333
#define pii pair<int,int>

struct node { int t,v,op,next; }a[100010];

queue<int> q;

int ans1[110][110],ans2[110][110];
int num[110][110],head[210],cur[210],level[210],n,m,vs,vt,tot;
bool vis[10010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void print(int x)
{
	static char s[233];
	if (!x) { putchar('0');putchar(' ');return; }
	int tot=0;
	for (;x;x/=10) s[++tot]=x%10+'0';
	for (;tot;tot--) putchar(s[tot]);
	putchar(' ');
}

inline void add(int x,int y,int z)
{
	a[++tot].t=y;a[tot].v=z;a[tot].op=tot+1;a[tot].next=head[x];head[x]=tot;
	a[++tot].t=x;a[tot].v=0;a[tot].op=tot-1;a[tot].next=head[y];head[y]=tot;
}

inline bool bfs()
{
	while (!q.empty()) q.pop();
	memset(level,0,sizeof(level));
	level[vs]=1;cur[vs]=head[vs];q.push(vs);
	while (!q.empty())
	{
		int x=q.front();q.pop();
		for (int i=head[x];i;i=a[i].next) if (a[i].v)
		{
			int t=a[i].t;
			if (level[t]) continue;
			level[t]=level[x]+1;cur[t]=head[t];
			if (t==vt) return true;
			q.push(t);
		}
	}
	return false;
}

inline int dfs(int x,int y)
{
	if (x==vt||!y) return y;
	int res=0;
	for (int &i=cur[x];i;i=a[i].next) if (a[i].v)
	{
		int t=a[i].t;
		if (level[t]!=level[x]+1) continue;
		int hh=dfs(t,min(y,a[i].v));
		if (!hh) continue;
		res+=hh;y-=hh;
		a[i].v-=hh;a[a[i].op].v+=hh;
		if (!y) break;
	}
	return res;
}

inline void work(int id)
{
	memset(head,0,sizeof(head));tot=0;
	vs=0;vt=n*2+1;
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (!vis[num[i][j]]) add(i,(num[i][j]+m-1)/m+n,1);
	for (int i=1;i<=n;i++) add(vs,i,1),add(i+n,vt,1);
	while (bfs()) dfs(vs,inf);
	for (int i=1;i<=n;i++)
	{
		int now=0;
		for (int j=head[i];j;j=a[j].next) if (a[j].t>n&&!a[j].v) now=a[j].t-n;
		for (int j=1;j<=m;j++) if (!vis[num[i][j]]&&(num[i][j]+m-1)/m==now)
		{
			ans1[i][id]=num[i][j];vis[num[i][j]]=true;
			break;
		}
	}
}

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) num[i][j]=rd();
	for (int i=1;i<=m;i++) work(i);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++) print(ans1[i][j]);
		putchar('\n');
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++) for (int k=1;k<=n;k++) if (ans1[k][j]>(i-1)*m&&ans1[k][j]<=i*m) ans2[i][j]=ans1[k][j];
		for (int j=1;j<=m;j++) print(ans2[i][j]);
		putchar('\n');
	}
	return 0;
}