2009 Bulgarian Olympiad in Informatics
The mining company "Dries, fades, blossoms, but gives no fruits" got a concession for development of a diamond deposit - a right-angled cuboid sized meters. The geological research estimated the diamond carats in each cubic meter of the deposit. To decide how to develop the deposit, the economists and mining engineers consider many possibilities. They need help calculating the total count of diamond carats in given parts of the deposit. The parts are cuboids with sides parallel to the sides of the deposit. Write down a program diamonds to calculate the carats in the series of parts (not more than ) of the deposit.
Input Specification
On the first row are three integers , , and followed by the diamond carats in each cubic meter of the deposit as follows:
C1,1,1, C1,1,2, ..., C1,1,L, C1,2,1, C1,2,2, ..., C1,2,L, ... C1,M,1, C1,M,2, ..., C1,M,L, C2,1,1, C2,1,2, ..., C2,1,L, ... C2,M,1, C2,M,2, ..., C2,M,L, ... CN,M,1, CN,M,2, ..., CN,M,L
where carats. On each of the following lines of input are 6 integers - the coordinates of two opposite vertices of a part of the deposit for which the total quantity of carats should be calculated.
Output Specification
For each part of the deposit given in the input, the program has to print a single number - the quantity of the carats in this part.
Sample Input
3 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
0 0 0 3 3 2
1 0 1 3 2 2
Sample Output
171
52
Comments