The 2021 China Collegiate Programming Contest (Harbin) J. Local Minimum

题目链接:Problem - J - Codeforces

Given a matrix of size n×mn×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

∑i=1n∑j=1m[min{Mu,v|u=iorv=j}=Mi,j]∑i=1n∑j=1m[min{Mu,v|u=iorv=j}=Mi,j]

Note: [A]=1 if statement A is true, or [A]=0.

Input

The first line contains two integers n,m(1≤n,m≤1000), denoting the size of given matrix.

Following nn lines each contains mm integers Mi,j(1≤Mi,j≤106), denoting the given matrix.

Output

Output one line containing one integer, denoting the answer.

Example

input

3 3
1 5 9
4 3 7
2 6 2

output

3

Note

There are 3 entries M1,1=1,M2,2=3,M

你可能感兴趣的:(c++,c语言)