409158: GYM103447 J Local Minimum
Description
Given a matrix of size $$$n\times m$$$. Determine the number of entries who equals the minimum value among all other entries of the same row or column. Formally, determine the value of $$$$$$\sum_{i=1}^{n}\sum_{j=1}^{m}\left[\min\{M_{u, v} \, | \, u = i \; \mathrm{or} \; v = j \} = M_{i, j}\right]$$$$$$
Note: $$$[A] = 1$$$ if statement $$$A$$$ is true, or $$$[A] = 0$$$.
InputThe first line contains two integers $$$n,m \, (1 \le n,m \le 1000)$$$, denoting the size of given matrix.
Following $$$n$$$ lines each contains $$$m$$$ integers $$$M_{i,j} \, (1\le M_{i,j} \le 10^6)$$$, denoting the given matrix.
OutputOutput one line containing one integer, denoting the answer.
ExampleInput3 3 1 5 9 4 3 7 2 6 2Output
3Note
There are 3 entries $$$M_{1,1} = 1, M_{2,2} = 3, M_{3,3} = 2$$$ satisfying the constraint.