#B4127. Knowledge Level Rearrangement

    ID: 11784 Type: Default 1000ms 256MiB

Knowledge Level Rearrangement

Knowledge Level Rearrangement

A class of students is arranged in an n×mn\times m grid. The student in the ii-th row (from the front) and jj-th column (from the left) has a knowledge level ai,ja_{i,j}.

In a single adjustment process, the teacher does the following:

  1. Compute the sum of knowledge levels for each column. Identify all columns whose sum is equal to the maximum or the minimum among all column sums.
  2. All students in these identified columns leave their seats and line up in the corridor ordered by their knowledge levels in descending order.
  3. The evacuated students then sit back in the empty seats following a snake-like order: filling the grid row by row, where in odd-numbered rows (1-indexed) seats are filled from left to right, and in even-numbered rows from right to left.

Given the initial seating arrangement and an integer $k$, perform the adjustment process $k$ times and output the final seating arrangement.

inputFormat

The input consists of multiple lines:

  • The first line contains three integers $n$, $m$, and $k$ ($1\le n, m\le 100$, $0\le k\le 1000$) — the number of rows, columns, and the number of adjustments to perform.
  • Each of the next $n$ lines contains $m$ integers, where the $j$-th integer in the $i$-th line represents $a_{i,j}$, the knowledge level of the student at row $i$ and column $j$.

outputFormat

Output the final seating arrangement after kk adjustments. Each of the nn lines should contain mm integers separated by a space.

sample

3 3 1
3 1 2
2 4 1
5 3 3
5 1 3

2 4 3 2 3 1

</p>