#P5729. Glass Cube Laser Cutting

    ID: 18957 Type: Default 1000ms 256MiB

Glass Cube Laser Cutting

Glass Cube Laser Cutting

A solid glass cuboid is composed of small $1 \times 1 \times 1$ cubes, arranged in a block with width $w$, length $x$, and height $h$. Each small cube has coordinates $(i,j,k)$ with i in $[1,w]$, j in $[1,x]$, and k in $[1,h]$.

You are given a sequence of $q$ cutting operations. Each operation provides 6 integers: $(x_1,y_1,z_1,x_2,y_2,z_2)$, with \(x_1 \le x_2,\; y_1 \le y_2,\; z_1 \le z_2\). In every operation, a laser is used to remove a cuboid‐shaped hole in the block. The two opposite corners of the hole are exactly $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$; that is, every small cube with coordinates satisfying \[ x_1 \le i \le x_2,\quad y_1 \le j \le y_2,\quad z_1 \le k \le z_2 \] is vaporized.

For example, if you have a $4\times4\times4$ cube (with total volume 64) and perform one cut with parameters $(1,1,1)$ and $(2,2,2)$, then the $8$ cubes in the middle are removed and the remaining volume is $56$.

Your task is to determine the volume (i.e. the number of $1\times1\times1$ cubes) that remains after all the cutting operations are performed.

inputFormat

Input begins with a line containing three integers $w$, $x$, and $h$ --- the dimensions of the cuboid.

The next line contains an integer $q$, the number of cutting operations.

Each of the following $q$ lines contains six integers: $x_1$, $y_1$, $z_1$, $x_2$, $y_2$, $z_2$, describing a cutting operation. It is guaranteed that \(x_1 \le x_2,\; y_1 \le y_2,\; z_1 \le z_2\). All coordinates are 1-indexed.

outputFormat

Output a single integer --- the remaining number of $1\times1\times1$ cubes after all cuts have been made.

sample

4 4 4
1
1 1 1 2 2 2
56

</p>