The Summing SquareEasy

The Summing Square

Easy+10 XP · +5 Auramatrixloopssummation

UptoSkills Arena's canteen serves delicious rice bowls. The bowls are arranged in a square grid. The manager wants to know the total amount of rice (in grams) in a specific square sub-section of the grid. Given the grid dimensions and the top-left corner and size of the sub-square, calculate the total rice.

Let the grid be represented by a 2D array G where G[i][j] is the amount of rice in grams at row i and column j.

You are given the grid, and three integers r, c, and k. You need to calculate the sum of all elements in the square subgrid starting at row r, column c with side length k.

Input

First line: two integers N, M (grid dimensions). Next N lines: M integers each, representing the grid. Last line: three integers r, c, k (top-left corner row and column, and side length). Rows and columns are 0-indexed.

Output

A single integer: the sum of elements in the specified sub-square.

Constraints

1 <= N, M <= 100 0 <= G[i][j] <= 1000 0 <= r < N 0 <= c < M 1 <= k r + k <= N c + k <= M

Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests

Example 1

Input
3 4
1 2 3 4
5 6 7 8
9 10 11 12
1 1 2
Output
34

Sum of the 2x2 square starting at (1,1): 6 + 7 + 10 + 11 = 34.

Example 2

Input
2 2
10 20
30 40
0 0 1
Output
10

Sum of the 1x1 square starting at (0,0): 10.

Hints