Singlazy and Chocolates

All submissions for this problem are available.
Singlazy recently returned from his foreign vacation. He got excited at the airport and bought a huge cuboidal box (with sides AxBxC) of chocolates. However, the distribution of chocolates inside this box is not uniform. Consider the box to have a 3D coordinate system within it. Suppose you break the cuboidal box into many cubes of dimensions 1x1x1, you can then label coordinates starting from 0, 0, 0 to A, B, C .
You are given a matrix of the chocolates in each individual cube. To take out chocolates from the box he needs to put his hand in a particular area. He has a huge hand, so this area can be anywhere between 0x0x0 to AxBxC, depending on his mood. Singlazy is as his name suggests, lazy. Before drawing chocolates from an area he wants to know how many chocolates he will get from the area. He however does not extract these chocolates, he is simply collecting information.
You are given the number of chocolates in each coordinate in the 3D box. You are then given Q queries, describing the area about which Singlazy wants to know. Output the answers to the queries.
Input
First line has 3 integers: A, B, C
The next line has the number of chocolates in each coordinate defined as Ch(A1, B1, C1)
Ch1,1,1, Ch1,1,2, ..., Ch1,1,A,
Ch1,2,1, Ch1,2,2, ..., Ch1,2,A,
...
Ch1,B,1, Ch1,B,2, ..., Ch1,B,A,
Ch2,1,1, Ch2,1,2, ..., Ch2,1,A,
...
Ch2,B,1, Ch2,B,2, ..., Ch2,B,A,
...
ChC,B,1, ChC,B,2, ..., ChC,B,A
The next line contains an integer Q, the number of Queries.
The following Q lines have 6 integers A1, B1, C1, A2, B2, C2  the coordinates of two opposite vertices of a part of the box for which the total quantity of chocolates should be calculated.
Output
Output description.
For each query, output a single line with the number of chocolates in the area queried.
Constraints
1 <= A, B, C <= 100Chi,j,k ≤ 2000 chocolates
Subtask 1 (20 points):
Q<=10
Subtask 2 (80 points):
Q<=10^5
Example
Input: 3 3 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 2 0 0 0 3 3 2 1 0 1 3 2 2 Output: 171 52Explanation For the first query, Singla can access all cubes between the coordinates 0, 0, 0 and 3, 3, 2. Thus the answer is the sum of all the chocolates in the individual cubes.
For the second query, He can Take chocolates from cubes only between the coordinates (1, 0, 1) and (3, 2, 2). You can verify that these add up to 52. The break up being: 11 + 12 + 14 + 15.
Author:  harrycoda 
Tags  harrycoda 
Date Added:  17112017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions