409158: GYM103447 J Local Minimum

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Local Minimumtime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard output

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$$$.

Input

The 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.

Output

Output one line containing one integer, denoting the answer.

ExampleInput
3 3
1 5 9
4 3 7
2 6 2
Output
3
Note

There are 3 entries $$$M_{1,1} = 1, M_{2,2} = 3, M_{3,3} = 2$$$ satisfying the constraint.

加入题单

上一题 下一题 算法标签: