LearnPy Hub
← Arena
IntermediateRating 1300

Sum of a Rectangle

Answer q questions: what is the sum of the rectangle with corners (r1, c1) and (r2, c2) (rows and columns counted from 1)?

Input

n and m; n rows; q; q lines 'r1 c1 r2 c2'.

Output

q lines.

Sample 1

Input
3 3
1 2 3
4 5 6
7 8 9
2
1 1 2 2
2 2 3 3
Output
12
28

Sample 2

Input
1 11
-3 -2 7 6 8 6 6 2 4 3 8
20
1 2 1 10
1 5 1 7
1 6 1 9
1 3 1 9
1 3 1 10
1 8 1 10
1 6 1 8
1 2 1 6
1 6 1 10
1 6 1 7
1 4 1 8
1 1 1 11
1 2 1 8
1 10 1 10
1 1 1 2
1 2 1 4
1 9 1 11
1 3 1 4
1 6 1 10
1 1 1 6
Output
40
20
18
39
42
9
14
25
21
12
28
45
33
3
-5
11
15
13
21
22
solution.py
Output appears here
Sum of a Rectangle · Python Arena problem · LearnPy Hub