Matrix Saddle PointsEasy

Matrix Saddle Points

EasyPractice library · +10 XPmatrixgridtraversal

Given an N x M matrix (2D grid) of integers, find all saddle points. A saddle point is an element which is the minimum in its row and the maximum in its column. If multiple saddle points exist, output them in any order. If no saddle points exist, output 'No saddle points'.

Input

The first line contains two integers N and M, the dimensions of the matrix. The next N lines each contain M space-separated integers representing the elements of the matrix.

Output

Print the coordinates (row, column) of each saddle point, separated by spaces. Row and column are 0-indexed. If no saddle points exist, print 'No saddle points'.

Constraints

1 <= N, M <= 1000. The values in the matrix are integers between -10^9 and 10^9.

Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests

Example 1

Input
3 3
1 2 3
4 5 6
7 8 9
Output
2 0

Element 7 is min in its row (row 2) and max in its column (column 0). Coordinates are (2, 0).

Example 2

Input
2 2
3 3
3 3
Output
0 0 0 1 1 0 1 1

All elements are saddle points as they are minimum in their row and maximum in their column. Coordinates are (0, 0), (0, 1), (1, 0), (1, 1).

Hints