Cube Dividing

Count the face-connected components of unit cubes left in an A x B x C box after removing N given cubes, where the box is huge but N is at most 20000.

Hard8GraphBFSDFSHash mapNo attempts yetTime limit5sMemory limit512 MB

Problem

Pablo Cubarson is a cubism artist. His new piece starts from a cuboid made of A×B×CA \times B \times C unit cubes. He plans to carve the shape he wants by removing NN of those unit cubes. Just before starting, he noticed that the removal can split the remaining material into several parts that no longer touch each other. A piece that falls apart into several parts goes against his sense of beauty, so he wants to know how many parts his plan produces.

Count the connected components formed by the unit cubes that remain after the NN cubes are removed. Two cubes are connected when they share a face.

Input

The input is a single test case in the following format.

A B C N
X1 Y1 Z1
...
XN YN ZN

The first line contains the integers AA, BB, CC and NN. AA, BB and CC (1A,B,C1061 \le A, B, C \le 10^6) give the size of the cuboid: it is AA units wide from left to right, BB units tall from bottom to top, and CC units deep from front to back. NN (0N200000 \le N \le 20000, NA×B×C1N \le A \times B \times C - 1) is the number of cubes that are removed.

Each of the next NN lines contains the integers XiX_i (0XiA10 \le X_i \le A-1), YiY_i (0YiB10 \le Y_i \le B-1) and ZiZ_i (0ZiC10 \le Z_i \le C-1). They mean that the cube XiX_i steps from the left, YiY_i steps from the bottom and ZiZ_i steps from the front is removed. Coordinates count from 0. All given positions are distinct.

Output

Print the number of connected components that remain after the listed cubes are removed.