Hide

Problem H
Bee House Perimeter

Alice is a queen bee living in Beeland (a honeycomb structure described by $R$, the number of cells of the side of honeycomb). The cells in Beeland are numbered from $1$ to $R^3 - (R-1)^3$ in row major order. For example for $R = 3$, the Beeland that Alice lives in looks like this:

\includegraphics[width=3cm]{beeland.png}

Now Alice lives in a house that occupies $K$ adjacent cells in Beeland. You are Bob, the knight bee. You need to protect Alice’s house, but first you need to know the length of its outer perimeter (the number of outermost sides of Alice’s house). The illustration below shows the visualizations of Sample Inputs/Outputs $2$ and $3$.

\includegraphics[width=8cm]{beeland23.png}

Input

The first line of input consists of two integers: $R$ and $K$. ($1 \leq R \leq 50$, $1 \leq K \leq R^3 - (R-1)^3$). The second line contains $K$ unique integers that describe the indices of Alice’s house, where each integer is in the range $[1,R^3-(R-1)^3]$.

Output

Print an integer in one line: The perimeter of Alice’s house.

Sample Input 1 Sample Output 1
3 1
7
6
Sample Input 2 Sample Output 2
3 6
5 6 7 11 15 18
24
Sample Input 3 Sample Output 3
3 7
5 6 11 15 18 14 9
20

Please log in to submit a solution to this problem

Log in