Company: Visa iit roorkee
Difficulty: medium
Matrix Block Sum You are given a matrix mat with m rows and n columns, and an integer k . Build a matrix answer of the same shape, where answer[i][j] is the sum of every element mat[r][c] whose position satisfies both i - k <= r <= i + k , and j - k <= c <= j + k , and which is a real position of the matrix, that is 0 <= r <= m - 1 and 0 <= c <= n - 1 . In words: centre a square block of side 2k + 1 on the cell (i, j) , cut away whatever hangs over the edge of the matrix, and add up what is left. The centre cell itself is always part of its own block. Input Format The first line contains three integers m , n and k — the number of rows, the number of columns, and the block radius. Each of the next m lines contains n integers — the row mat[i][0] ... mat[i][n-1] . Output Format Print m lines of n space-separated integers: the matrix answer . Constraints 1 <= m <= 40 1 <= n <= 40 0 <= k <= 100 -10^4 <= mat[i][j] <= 10^4 Examples Example 1 Inp