You are given a checkerboard with
Given the coordinates of two squares on the checkerboard, find the alternating sum of all of the numbers within the rectangle delimited by those two squares. By alternating sum what is meant is that we add all numbers in squares with the same colour as the first square given, and subtract all numbers with the opposite colour.
Input Specification
The first line of the input file contains the integers
A number of input lines then follow. Each line contains three
space-separated integers
Following this are a number of lines containing queries. Each line
contains four space-separated integers:
Output Specification
Print the answer to each query on its own line, in order.
Sample Input
3 3
1 2 5
3 1 -2
2 3 11
0 0 0
2 1 3 3
0 0 0 0
Sample Output
13
Sample Explanation
The checkerboard is three cells by three cells. Here's what it looks like:
0 5 0
0 0 11
-2 0 0
We are asked to find the alternating sum of the second and third rows.
The
Comments