#B3662. Mountain Peaks After Land Swaps

    ID: 11321 Type: Default 1000ms 256MiB

Mountain Peaks After Land Swaps

Mountain Peaks After Land Swaps

In Berland Kingdom, the land is represented as an n×mn \times m grid. The cell at row ii and column jj initially has an altitude of ai,ja_{i,j}. Over a long period, there are TT geological events. In each event, the altitudes of two specified cells are swapped.

A cell is called a mountain peak if its altitude is strictly greater than the altitudes of all its directly adjacent neighbors (up, down, left, and right; if a neighbor does not exist, it is ignored).

After all swaps, you are to determine how many mountain peaks exist and output their coordinates. The cells are indexed starting from 1.

inputFormat

The first line contains three integers nn, mm, and TT (1n,m10001 \le n, m \le 1000, 0T1050 \le T \le 10^5), representing the number of rows, columns, and the number of swap events respectively.

The next nn lines each contain mm integers, where the jj-th integer in the ii-th line is ai,ja_{i,j}, the altitude of the cell at row ii, column jj.

Then TT lines follow, each containing four integers x1x_1, y1y_1, x2x_2, y2y_2, indicating that the altitudes of the cells at positions (x1,y1)(x_1,y_1) and (x2,y2)(x_2,y_2) are to be swapped.

outputFormat

Output the total number of mountain peaks in the grid after all swaps. Then, output the coordinates of each mountain peak in separate lines in the format row column. The order of peaks can be arbitrary.

sample

3 3 0
1 2 3
1 4 2
1 1 2
2

1 3 2 2

</p>