Bulgarian OI '09 P6 - Diamonds

View as PDF

Submit solution

Points: 12
Time limit: 1.0s
Memory limit: 32M

Problem type
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 L \times M \times N 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 500\,000) of the deposit.

Input Specification

On the first row are three integers L, M, and N (0 < L,M,N \le 100) 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 C_{i,j,k} \le 2\,000 carats. On each of the following lines of input are 6 integers x_1, y_1, z_1, x_2, y_2, z_2 (0 \le x_1 < x_2 \le L, 0 \le y_1 < y_2 \le M, 0 \le z_1 < z_2 \le N) - 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

There are no comments at the moment.