#include #include #include struct Dim { char _[32][32][32]; }; static int neighbors(const struct Dim *d, int z, int y, int x) { int active = 0; for (int i = -1; i <= +1; ++i) for (int j = -1; j <= +1; ++j) for (int k = -1; k <= +1; ++k) { if (!i && !j && !k) continue; active += (d->_[z+i&31][y+j&31][x+k&31] == '#'); } return active; } static struct Dim step(const struct Dim *prev) { struct Dim next; for (int z = 0; z < 32; ++z) for (int y = 0; y < 32; ++y) for (int x = 0; x < 32; ++x) { int active = neighbors(prev, z, y, x); if (prev->_[z][y][x] == '#') { next._[z][y][x] = (active == 2 || active == 3 ? '#' : '.'); } else { next._[z][y][x] = (active == 3 ? '#' : '.'); } } return next; } int main(void) { struct Dim init = {0}; for (int y = 0;; ++y) { if (scanf("%s\n", init._[0][y]) < 1) break; } struct Dim prev = init; for (int i = 0; i < 6; ++i) { struct Dim next = step(&prev); prev = next; } int active = 0; for (int z = 0; z < 32; ++z) for (int y = 0; y < 32; ++y) for (int x = 0; x < 32; ++x) { active += (prev._[z][y][x] == '#'); } printf("%d\n", active); }