Codeforces Round 345 (Div. 2)
E
Table Compression
Codeforces
未评级
原题
← D→
翻译中…

Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis.

翻译中…

Petya decided to compress tables. He is given a table $*a*$ consisting of $*n*$ rows and $*m*$ columns that is filled with positive integers. He wants to build the table $*a*'$ consisting of positive integers such that the relative order of the elements in each row and each column remains the same. That is, if in some row $*i*$ of the initial table $*a*_{*i*, *j*} < *a*_{*i*, *k*}$, then in the resulting table $*a*'_{*i*, *j*} < *a*'_{*i*, *k*}$, and if $*a*_{*i*, *j*} = *a*_{*i*, *k*}$ then $*a*'_{*i*, *j*} = *a*'_{*i*, *k*}$. Similarly, if in some column $*j*$ of the initial table $*a*_{*i*, *j*} < *a*_{*p*, *j*}$ then in compressed table $*a*'_{*i*, *j*} < *a*'_{*p*, *j*}$ and if $*a*_{*i*, *j*} = *a*_{*p*, *j*}$ then $*a*'_{*i*, *j*} = *a*'_{*p*, *j*}$.

翻译中…

Because large values require more space to store them, the maximum value in $*a*'$ should be as small as possible.

翻译中…

Petya is good in theory, however, he needs your help to implement the algorithm.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ (image, the number of rows and the number of columns of the table respectively.

翻译中…

Each of the following $*n*$ rows contain $*m*$ integers $*a*_{*i*, *j*}$ $(1 ≤ *a*_{*i*, *j*} ≤ 10^{9})$ that are the values in the table.

翻译中…

Output

翻译中…

Output the compressed table in form of $*n*$ lines each containing $*m*$ integers.

翻译中…

If there exist several answers such that the maximum number in the compressed table is minimum possible, you are allowed to output any of them.

翻译中…

Note

翻译中…

In the first sample test, despite the fact $*a*_{1, 2} ≠ *a*_{21}$, they are not located in the same row or column so they may become equal after the compression.

翻译中…

样例

Input #1
2 2
1 2
3 4
Output #1
1 2
2 3
InputCopy OutputCopy
Input #2
4 3
20 10 30
50 40 30
50 60 70
90 80 70
Output #2
2 1 3
5 4 3
5 6 7
9 8 7
InputCopy OutputCopy
题目信息
题号
651E
时间限制
4 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。