#K54807. Submatrix Sum

    ID: 29835 Type: Default 1000ms 256MiB

Submatrix Sum

Submatrix Sum

Given a matrix of integers of size \(n \times m\), you are required to compute the sum of the elements in a submatrix defined by its upper-left coordinate \((r_1, c_1)\) and lower-right coordinate \((r_2, c_2)\). The sum can be mathematically represented as:

[ S = \sum_{i=r_1}^{r_2} \sum_{j=c_1}^{c_2} matrix[i][j] ]

Your task is to read the matrix from standard input and compute the sum for the specified submatrix.

inputFormat

The input is given via standard input in the following format:

  • The first line contains two integers \(n\) and \(m\) separated by a space, representing the number of rows and columns of the matrix.
  • The next \(n\) lines each contain \(m\) space-separated integers representing the matrix.
  • The next line contains two integers representing the upper-left coordinate \(r_1\) and \(c_1\) (0-indexed).
  • The final line contains two integers representing the lower-right coordinate \(r_2\) and \(c_2\) (0-indexed).

You can assume that the input coordinates are valid and \(r_1 \le r_2\), \(c_1 \le c_2\).

outputFormat

Output a single integer which is the sum of the elements in the specified submatrix. The result should be printed to standard output.

## sample
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
1 1
2 2
34