Farmer John's cows have finally blasted off from Earth and are now drifting through space in their Moocraft. To reach their kin on Io, a moon of Jupiter, they must first cross a dangerous asteroid belt.
Bessie is piloting the craft through an $N \times N \times N$ ($1 \le N \le 100$) sector of space. Every asteroid in the sector is a group of $1 \times 1 \times 1$ blocks of space-rock joined face to face. Two blocks that touch only along an edge, or only at a single corner, belong to different asteroids.
Count the number of distinct asteroids in the sector.
The sector is given as $N$ square slices stacked one behind another (front to back). Each slice is an $N \times N$ grid in which * marks a block of space-rock and . marks empty space. A block at slice $s$, row $r$, column $c$ shares a face with the blocks at $(s\pm1, r, c)$, $(s, r\pm1, c)$, and $(s, r, c\pm1)$, and blocks joined this way belong to the same asteroid.
For example, consider a $3 \times 3 \times 3$ sector. Here M marks the Moocraft's start at $(1,1,1)$ and D marks the destination at $(3,3,3)$; these markers only help orient the map and are not needed to solve the problem.
Close slice Middle slice Far Slice Assembled with overlaps
+---+ +---+ +---+ +---+ Far
|M..| |..*| |...| |...|
|.*.| |.*.| |.*.| +---+.|
|...| |*..| |..D| |..*|D|
+---+ +---+ +---+ +---+.|-+
|M..|.|
|.*.|-+
|...|
Close +---+
Visual inspection shows three asteroids, including a long one running straight through the middle of the sector. The next figure labels each block with the number of the asteroid it belongs to:
+---+ Far
/|...|
/ |.1.|
/ |...|
/ +---+
+---+ /
/|..3| /
/ |.1.| /
/ |2..|/
/ +---+
+---+ /
|...| /
|.1.| /
|...|/
Close +---+
* (a block of space-rock) or . (empty space).