Sixteen piles of cheese are put on a 4x4 square. They're labeled from \$1\$ to \$16\$. The smallest pile is \$1\$ and the biggest one is \$16\$.
The Hungry Mouse is so hungry that it always goes straight to the biggest pile (i.e. \$16\$) and eats it right away.
After that, it goes to the biggest neighboring pile and quickly eats that one as well. (Yeah ... It's really hungry.) And so on until there's no neighboring pile anymore.
A pile may have up to 8 neighbors (horizontally, vertically and diagonally). There's no wrap-around.
Example
We start with the following piles of cheese:
$$\begin{matrix} 3&7&10&5\\ 6&8&12&13\\ 15&9&11&4\\ 14&1&16&2 \end{matrix}$$
The Hungry Mouse first eats \$16\$, and then its biggest neighbor pile, which is \$11\$.
$$\begin{matrix} 3&7&10&5\\ 6&8&12&13\\ 15&9&🐭&4\\ 14&1&\color{grey}\uparrow&2 \end{matrix}$$
Its next moves are \$13\$, \$12\$, \$10\$, \$8\$, \$15\$, \$14\$, \$9\$, \$6\$, \$7\$ and \$3\$ in this exact order.
$$\begin{matrix} 🐭&\color{grey}\leftarrow&\small\color{grey}\swarrow&5\\ \small\color{grey}\nearrow&\small\color{grey}\swarrow&\color{grey}\uparrow&\color{grey}\leftarrow\\ \color{grey}\downarrow&\small\color{grey}\nwarrow&\small\color{grey}\nearrow&4\\ \small\color{grey}\nearrow&1&\color{grey}\uparrow&2 \end{matrix}$$
There's no cheese anymore around the Hungry Mouse, so it stops there.
The challenge
Given the initial cheese configuration, your code must print or return the sum of the remaining piles once the Hungry Mouse has stopped eating them.
For the above example, the expected answer is \$12\$.
Rules
- Because the size of the input matrix is fixed, you may take it as either a 2D array or a one-dimensional array.
- Each value from \$1\$ to \$16\$ is guaranteed to appear exactly once.
- This is code-golf.
Test cases
[ [ 4, 3, 2, 1], [ 5, 6, 7, 8], [12, 11, 10, 9], [13, 14, 15, 16] ] --> 0
[ [ 8, 1, 9, 14], [11, 6, 5, 16], [13, 15, 2, 7], [10, 3, 12, 4] ] --> 0
[ [ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16] ] --> 1
[ [10, 15, 14, 11], [ 9, 3, 1, 7], [13, 5, 12, 6], [ 2, 8, 4, 16] ] --> 3
[ [ 3, 7, 10, 5], [ 6, 8, 12, 13], [15, 9, 11, 4], [14, 1, 16, 2] ] --> 12
[ [ 8, 9, 3, 6], [13, 11, 7, 15], [12, 10, 16, 2], [ 4, 14, 1, 5] ] --> 34
[ [ 8, 11, 12, 9], [14, 5, 10, 16], [ 7, 3, 1, 6], [13, 4, 2, 15] ] --> 51
[ [13, 14, 1, 2], [16, 15, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12] ] --> 78
[ [ 9, 10, 11, 12], [ 1, 2, 4, 13], [ 7, 8, 5, 14], [ 3, 16, 6, 15] ] --> 102
[ [ 9, 10, 11, 12], [ 1, 2, 7, 13], [ 6, 16, 4, 14], [ 3, 8, 5, 15] ] --> 103
[[9, 10, 11, 12], [1, 2, 7, 13], [6, 16, 4, 14], [3, 8, 5, 15]]
\$\endgroup\$