Company: visa_9oct
Difficulty: medium
Nearly Regular Crosses You are given a rectangular matrix of integers with n rows and m columns. Picking one row r and one column c traces out a cross : the cross consists of every cell of row r together with every cell of column c . The two arms meet at the single cell matrix[r][c] , called the intersection of the cross. There are exactly n * m crosses, one for each pair (r, c) . A cross is regular when all of its cells hold the same value. A cross is nearly regular when all of its cells hold the same value except possibly the cell at the intersection , which is free to hold anything. A regular cross is therefore also nearly regular. Count the nearly regular crosses of the matrix. Input Format The first line contains two integers n and m — the number of rows and the number of columns. Each of the next n lines contains m integers — the entries of one row of the matrix. Output Format Print a single integer — the number of nearly regular crosses. Constraints 1 <= n , 1 <= m n * m &