eolymp
bolt
Try our new interface for solving problems

UFOs

Vasya is a ufologist and his duties include observing Unidentified Flying Objects (UFOs) in the part of space bounded by a cube \textbf{N}×\textbf{N}×\textbf{N}. The cube is divided into cubic sectors \textbf{1}×\textbf{1}×\textbf{1}. During the observation, the following events may happen: \begin{itemize} \item several new UFOs emerge in a certain sector; \item several UFOs disappear in a certain sector; \item Vasya's boss may ask him how many UFOs there are in a part of space consisting of several sectors. \end{itemize} At the moment when Vasya starts his observations there are no UFOs in the whole space. \InputFile The first line contains an integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{128}). The coordinates of sectors are integers from \textbf{0} to \textbf{N--1}. Then there are entries describing events, one entry per line. Each entry starts with a number \textbf{M}. \begin{itemize} \item If \textbf{M} is \textbf{1}, then this number is followed by four integers \textbf{x} (\textbf{0} ≤ \textbf{x} < \textbf{N}), \textbf{y} (\textbf{0} ≤ \textbf{y} < \textbf{N}), \textbf{z} (\textbf{0} ≤ \textbf{z} < \textbf{N}), \textbf{K} (\textbf{--20000} ≤ \textbf{K} ≤\textbf{20000}), which are coordinates of a sector and the change in the number of UFOs in this sector. The number of UFOs in a sector cannot become negative. \item If \textbf{M} is \textbf{2}, then this number is followed by six integers \textbf{x_1}, \textbf{y_1}, \textbf{z_1}, \textbf{x_2}, \textbf{y_2}, \textbf{z_2} (\textbf{0} ≤ \textbf{x_1} ≤ \textbf{x_2} < \textbf{N}, \textbf{0} ≤ \textbf{y_1} ≤ \textbf{y_2} < \textbf{N}, \textbf{0} ≤ \textbf{z_1}≤ \textbf{z_2} < \textbf{N}), which mean that Vasya must compute the total number of UFOs in sectors (\textbf{x}, \textbf{y}, \textbf{z}) belonging to the volume: \textbf{x_1} ≤ \textbf{x} ≤ \textbf{x_2}, \textbf{y_1} ≤ \textbf{y} ≤ \textbf{y_2}, \textbf{z_1} ≤ \textbf{z} ≤ \textbf{z_2}. \item If \textbf{M} is \textbf{3}, it means that Vasya is tired and goes to sleep. This entry is always the last one. \end{itemize} The number of entries does not exceed \textbf{100002}. \OutputFile For each query, output in a separate line the required number of UFOs.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
1 0 0 0 10
1 0 0 0 15
2 0 0 0 0 0 0
1 0 0 0 -9
1 0 0 0 5
1 0 0 0 -10
2 0 0 0 0 0 0
1 0 0 0 -1
2 0 0 0 0 0 0
3
Output example #1
25
11
10
Author Dmitry Zhukov
Source Ural SU and Orel STU Contest. Petrozavodsk Summer Session, August 2006