You are given a checkerboard with rows and columns .
Each square initially has the number zero written in it. For top-secret
strategic reasons which are given out on a need-to-know basis only (and
you do not, at the present moment, need to know) you must write a
program that will perform two types of operation:
Modify: Given the row and column of a square on the checkerboard, change the number written in it to a new value.
Query: 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.
The first line of the input file contains the integers and .
A number of input lines then follow. The integer at the beginning of the line signifies:
: End of input.
: A modify operation. Three integers follow: , , and , indicating that the value is to be written in row and column .
: A query. Four integers follow: , , , and . Output the alternating sum of all squares contained within the box , as described.
There will never be more than commands given.
For each query operation, print the answer on its own line.
3 3 1 1 2 5 1 3 1 -2 2 1 1 2 3 1 2 3 11 2 2 1 3 3 0
The checkerboard is three cells by three cells. When the first query is executed, the board looks like this:
0 5 0 0 0 0 -2 0 0
We are asked to find the alternating sum of the first two rows. Since the is on a square of opposite colour to the first square, it is subtracted to obtain an answer of . For the second query, the board looks like:
0 5 0 0 0 11 -2 0 0
Now, we take the alternating sum of the second and third rows. is added, whereas is subtracted, to give the answer .