Company: Wipro_16may
Difficulty: medium
Equal Sum Rectangular Areas You are given a matrix A of integers with R rows and C columns. Rows are numbered 0 to R-1 and columns 0 to C-1 . A rectangular area is chosen by picking a row range r1 <= r2 and a column range c1 <= c2 ; it consists of every cell A[i][j] with r1 <= i <= r2 and c1 <= j <= c2 . Every such choice is a distinct area, so two areas holding the same values but sitting at different positions are counted separately. An area is never empty, and the area covering the whole matrix is allowed. Count the rectangular areas whose sum equals the sum of all the cells outside them. For example, take A = [[1, 1, -2], [3, 2, 4], [-1, -2, -2]] . The two-cell area at positions (1, 2) and (2, 2) holds 4 and -2 , so its sum is 2 ; the nine cells minus those two also add up to 2 . That area therefore qualifies, and six more areas of A qualify as well, for a total of 7 . Input Format The first line holds two integers R and C . Each of the next R lines holds C intege