18. Larger than Neighbors

I'm a slow walker, but I never walk backwards.

Task Description

Write a program to read the number of rows ($r$) and columns ($c$) of a two-dimensional integer array, then read the array elements row by row. Finally print the elements that are greater than all of its neighbors. Note that an element can have at most $4$ neighbors. If there are multiple such elements, print them in the order of row by row, column by column.

讀入一個 $r$ 行 $c$ 列的二維整數陣列,找到那些格子上的數字皆大於它的鄰近格子上的數字,鄰近只有限制在它的上下左右四格。如果有多個答案,從上而下、由左而右依序印出。

Limits

Both $r$ and $c$ are no more than $100$.

Input Format

There are $r + 1$ lines in the input. The first line has $r$ and $c$. Each of the next $r$ lines has $c$ integers as a row in the matrix.

Output Format

There are $k$ lines in the output, where $k$ is the number of elements that are larger than its neighbors.

Sample Input

2 3
7 8 3
4 5 6

Sample Output

8
6

Discussion