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;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

#define MAX_V 210

//// bipartite match
int V;
multiset<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<V;i++)G[i].clear();
}

void add_edge(int u,int v){
  //printf("%d <=> %d\n", u,v);
  G[u].insert(v);
  G[v].insert(u);
}

void rem_edge(int u,int v){
  //printf("%d <=> %d\n", u,v);
  G[u].erase(G[u].find(v));
  G[v].erase(G[v].find(u));
}

bool dfs(int v){
  used[v]=true;
  for(int u : G[v]){
    int w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_match(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0; v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

int N,M;
vector<vector<int>> A;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin>>N>>M;
  vector<vector<vector<int>>> nums(N,vector<vector<int>>(N,vector<int>()));
  rep(i,N){
    vector<int> tmp(M);
    rep(j,M){
      cin>>tmp[j];
      tmp[j]--;
    }
    A.push_back(tmp);
  }

  init(2*N);
  rep(i,N){
    rep(j,M){
      nums[i][(A[i][j]/M)].push_back(A[i][j]);
      add_edge(i,(A[i][j]/M)+N);
    }
  }

  vector<vector<int>> resa(N,vector<int>(M,-1));
  rep(k,M){
    bipartite_match();
    rep(u,N){
      int v=match[u]-N;
      //dbg(u); dbg(v);
      int num=nums[u][v].back();
      nums[u][v].pop_back();
      resa[u][k]=num+1;
      rem_edge(u,v+N);
    }
  }

  vector<vector<int>> resb(N,vector<int>(M,-1));
  rep(j,M){
    vector<int> tmp;
    rep(i,N)tmp.push_back(resa[i][j]);
    sort(all(tmp));
    rep(i,N)resb[i][j]=tmp[i];
  }

  rep(i,N){
    rep(j,M)cout<<resa[i][j]<<" ";
    cout<<endl;
  }
  rep(i,N){
    rep(j,M)cout<<resb[i][j]<<" ";
    cout<<endl;
  }

  return 0;
}