All problems

Problem 710

Peak Element in a 2D Matrix

Medium · 20 pts · Matrix, Binary Search

Problem

A cell of a matrix is a peak if its value is strictly greater than each of its neighbours above, below, left and right (cells outside the matrix do not count as neighbours). Neighbouring cells always hold different values, so at least one peak exists. Print the row and column of the peak with the smallest row, breaking ties by the smallest column. A famous binary search over columns finds some peak in O(R log C), but here you must report this specific one.

Input

The first line contains R and C. Each of the next R lines contains C integers.

Output

Print the row and the column of the required peak (both counted from 0), separated by a space.

Constraints

1 <= R, C <= 500; 1 <= values <= 10^9; horizontally or vertically neighbouring cells hold different values

Example input

3 3
10 20 15
21 30 14
7 16 32

Example output

1 1

Explanation

In the matrix 10 20 15 / 21 30 14 / 7 16 32, the cell 30 at (1, 1) is larger than 20, 21, 14 and 16, and 32 at (2, 2) is also a peak. Row 0 has no peak, so the answer is 1 1.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Row with Maximum 1s Next: Largest Odd Number in a String