Problem 933
Count Servers that Communicate
Medium · 20 pts · Matrix, Counting
Problem
A grid shows where servers are: 1 means a server and 0 means an empty cell. Two servers can communicate if they are in the same row or the same column. Count the servers that can communicate with at least one other server. Count the servers in every row and every column first; then a server communicates exactly when its row count or its column count is at least 2.
Input
The first line contains R and C. Each of the next R lines is a row of C characters 0 or 1.
Output
Print the number of servers that communicate with another server.
Constraints
1 <= R, C <= 250
Example input
2 2 10 11
Example output
3
Explanation
In the grid 10 / 11, the two servers in column 0 communicate, and the bottom-right server shares row 1 with one of them. All three communicate, so the answer is 3.