{"problem":{"name":"Sorting a Grid","description":{"content":"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 co","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"agc037_d"},"statements":[{"statement_type":"Markdown","content":"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}$.\nYou need to rearrange these numbers as follows:\n\n1.  First, for each of the $N$ rows, rearrange the numbers written in it as you like.\n2.  Second, for each of the $M$ columns, rearrange the numbers written in it as you like.\n3.  Finally, for each of the $N$ rows, rearrange the numbers written in it as you like.\n\nAfter 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.\n\n## Constraints\n\n*   $1 \\leq N,M \\leq 100$\n*   $1 \\leq A_{ij} \\leq NM$\n*   $A_{ij}$ are distinct.\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$ $M$\n$A_{11}$ $A_{12}$ $...$ $A_{1M}$\n$:$\n$A_{N1}$ $A_{N2}$ $...$ $A_{NM}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"agc037_d","tags":[],"sample_group":[["3 2\n2 6\n4 3\n1 5","2 6 \n4 3 \n5 1 \n2 1 \n4 3 \n5 6"],["3 4\n1 4 7 10\n2 5 8 11\n3 6 9 12","1 4 7 10 \n5 8 11 2 \n9 12 3 6 \n1 4 3 2 \n5 8 7 6 \n9 12 11 10"]],"created_at":"2026-03-03 11:01:14"}}