~/algor $ cat problems/matritsa-egar-nuqtalari
Saddle points
Medium
1000 ms
128 MB
45%
An integer matrix of size $n \times m$ is given. An element is a saddle point if it is the smallest in its row and at the same time the largest in its column (its row or column may contain elements equal to it). Find the number of saddle points in the matrix.
Input
The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ integers.
Output
One integer — the number of saddle points.
Note
$1 \le n, m \le 200$
$-1000 \le a_{i,j} \le 1000$
Examples
Input #1
3 3 3 5 4 1 2 6 0 7 8
Output #1
1
Input #2
2 2 1 1 1 1
Output #2
4