407225: GYM102697 196 Cubical Classroom
Description
After the COVID-19 pandemic, a school decides to implement serious measures to ensure that students "socially distance" from each other. The school has divided each classroom into several squares, using glass walls, and each student is assigned to a single "sub-room" in the classroom.
Unfortunately, this strategy didn't accomodate enough students. To fix this, the school decided to stack several sub-rooms on top of each other, such that the sub-rooms form a cube. In other words, each classroom has $$$n^3$$$ sub-rooms, where $$$n$$$ is given as input.
Since everything was messed up by the COVID-19 quarantine, the school's classes all contain students of a wide range of ages. A student is called a leader if they're older than all of the students in adjacent sub-rooms, including diagonally (for example, a sub-room in the center of a classroom with $$$n=3$$$ would have 26 adjacent sub-rooms).
The teacher of the class wants to figure out which students are most likely to cause trouble. The teacher deduces that a student is likely to cause trouble if the following are true:
1. The student is not a leader (at least one student in an adjacent sub-room is older than them or the same age as them)
2. The student doesn't have any leaders in adjacent sub-rooms (including diagonally)
Given this information, help the teacher find out how many students in the classroom are likely to be troublemakers.
InputThe first line of input contains a single positive integer $$$n$$$: the number of sub-rooms in a single 1D cross-section of the classroom. There are $$$n^3$$$ sub-rooms and students in total.
The next $$$n$$$ lines each contain a 2D grid of space-separated integers: the ages of the students in each top-down cross-section of the classroom. Each cross-section will be separated by a new line.
OutputOutput a single integer $$$k$$$: the number of potential troublemakers in the 3D classroom.
ExamplesInput3 13 11 15 10 12 18 3 16 12 11 12 17 9 12 13 18 15 15 14 15 16 13 9 8 12 10 7Output
5Input
2 4 4 4 4 5 5 5 5Output
8