[Combinatorics]
Problem: Let $n$ be a given positive integer. In the Cartesian plane, each lattice point with nonnegative coordinates initially contains a butterfly, and there are no other butterflies. The neighborhood of a lattice point $c$ consists of all lattice points within the axis-aligned $(2 n+1) \times$ $(2 n+1)$ square centered at $c$, apart from $c$ itself. We call a butterfly lonely, crowded, or comfortable, depending on whether the number of butterflies in its neighborhood $N$ is respectively less than, greater than, or equal to half of the number of lattice points in $N$.

Every minute, all lonely butterflies fly away simultaneously. This process goes on for as long as there are any lonely butterflies. Assuming that the process eventually stops, determine the number of comfortable butterflies at the final state.

Solution: We always identify a butterfly with the lattice point it is situated at. For two points $p$ and $q$, we write $p \geqslant q$ if each coordinate of $p$ is at least the corresponding coordinate of $q$. Let $O$ be the origin, and let $\mathcal{Q}$ be the set of initially occupied points, i.e., of all lattice points with nonnegative coordinates. Let $\mathcal{R}_{\mathrm{H}}=\{(x, 0): x \geqslant 0\}$ and $\mathcal{R}_{\mathrm{V}}=\{(0, y): y \geqslant 0\}$ be the sets of the lattice points lying on the horizontal and vertical boundary rays of $\mathcal{Q}$. Denote by $N(a)$ the neighborhood of a lattice point $a$.

1. Initial observations. We call a set of lattice points up-right closed if its points stay in the set after being shifted by any lattice vector $(i, j)$ with $i, j \geqslant 0$. Whenever the butterflies form a up-right closed set $\mathcal{S}$, we have $|N(p) \cap \mathcal{S}| \geqslant|N(q) \cap \mathcal{S}|$ for any two points $p, q \in \mathcal{S}$ with $p \geqslant q$. So, since $\mathcal{Q}$ is up-right closed, the set of butterflies at any moment also preserves this property. We assume all forthcoming sets of lattice points to be up-right closed.

When speaking of some set $\mathcal{S}$ of lattice points, we call its points lonely, comfortable, or crowded with respect to this set (i.e., as if the butterflies were exactly at all points of $\mathcal{S}$ ). We call a set $\mathcal{S} \subset \mathcal{Q}$ stable if it contains no lonely points. In what follows, we are interested only in those stable sets whose complements in $\mathcal{Q}$ are finite, because one can easily see that only a finite number of butterflies can fly away on each minute.

If the initial set $\mathcal{Q}$ of butterflies contains some stable set $\mathcal{S}$, then, clearly no butterfly of this set will fly away. On the other hand, the set $\mathcal{F}$ of all butterflies in the end of the process is stable. This means that $\mathcal{F}$ is the largest (with respect to inclusion) stable set within $\mathcal{Q}$, and we are about to describe this set.

2. A description of a final set. The following notion will be useful. Let $\mathcal{U}=\left\{\vec{u}_{1}, \vec{u}_{2}, \ldots, \vec{u}_{d}\right\}$ be a set of $d$ pairwise non-parallel lattice vectors, each having a positive $x$ - and a negative $y$-coordinate. Assume that they are numbered in increasing order according to slope. We now define a $\mathcal{U}$-curve to be the broken line $p_{0} p_{1} \ldots p_{d}$ such that $p_{0} \in \mathcal{R}_{\mathrm{V}}, p_{d} \in \mathcal{R}_{\mathrm{H}}$, and $\vec{p}_{i-1} \vec{p}_{i}=\vec{u}_{i}$ for all $i=1,2, \ldots, m$ (see the Figure below to the left).

<img_3839>

Construction of $\mathcal{U}$-curve

<img_4021>

<img_3612>

Construction of $\mathcal{D}$



Now, let $\mathcal{K}_{n}=\{(i, j): 1 \leqslant i \leqslant n,-n \leqslant j \leqslant-1\}$. Consider all the rays emerging at $O$ and passing through a point from $\mathcal{K}_{n}$; number them as $r_{1}, \ldots, r_{m}$ in increasing order according to slope. Let $A_{i}$ be the farthest from $O$ lattice point in $r_{i} \cap \mathcal{K}_{n}$, set $k_{i}=\left|r_{i} \cap \mathcal{K}_{n}\right|$, let $\vec{v}_{i}=\overrightarrow{O A_{i}}$, and finally denote $\mathcal{V}=\left\{\vec{v}_{i}: 1 \leqslant i \leqslant m\right\}$; see the Figure above to the right. We will concentrate on the $\mathcal{V}$-curve $d_{0} d_{1} \ldots d_{m}$; let $\mathcal{D}$ be the set of all lattice points $p$ such that $p \geqslant p^{\prime}$ for some (not necessarily lattice) point $p^{\prime}$ on the $\mathcal{V}$-curve. In fact, we will show that $\mathcal{D}=\mathcal{F}$.

Clearly, the $\mathcal{V}$-curve is symmetric in the line $y=x$. Denote by $D$ the convex hull of $\mathcal{D}$.

3. We prove that the set $\mathcal{D}$ contains all stable sets. Let $\mathcal{S} \subset \mathcal{Q}$ be a stable set (recall that it is assumed to be up-right closed and to have a finite complement in $\mathcal{Q}$ ). Denote by $S$ its convex hull; clearly, the vertices of $S$ are lattice points. The boundary of $S$ consists of two rays (horizontal and vertical ones) along with some $\mathcal{V}_{*}$-curve for some set of lattice vectors $\mathcal{V}_{*}$.

Claim 1. For every $\vec{v}_{i} \in \mathcal{V}$, there is a $\vec{v}_{i}^{*} \in \mathcal{V}_{*}$ co-directed with $\vec{v}$ with $\left|\vec{v}_{i}^{*}\right| \geqslant|\vec{v}|$.

Proof. Let $\ell$ be the supporting line of $S$ parallel to $\vec{v}_{i}$ (i.e., $\ell$ contains some point of $S$, and the set $S$ lies on one side of $\ell$ ). Take any point $b \in \ell \cap \mathcal{S}$ and consider $N(b)$. The line $\ell$ splits the set $N(b) \backslash \ell$ into two congruent parts, one having an empty intersection with $\mathcal{S}$. Hence, in order for $b$ not to be lonely, at least half of the set $\ell \cap N(b)$ (which contains $2 k_{i}$ points) should lie in $S$. Thus, the boundary of $S$ contains a segment $\ell \cap S$ with at least $k_{i}+1$ lattice points (including $b$ ) on it; this segment corresponds to the required vector $\vec{v}_{i}^{*} \in \mathcal{V}_{*}$.

<img_3156>

Proof of Claim 1

<img_3490>

Proof of Claim 2

Claim 2. Each stable set $\mathcal{S} \subseteq \mathcal{Q}$ lies in $\mathcal{D}$.

Proof. To show this, it suffices to prove that the $\mathcal{V}_{*}$-curve lies in $D$, i.e., that all its vertices do so. Let $p^{\prime}$ be an arbitrary vertex of the $\mathcal{V}_{*}$-curve; $p^{\prime}$ partitions this curve into two parts, $\mathcal{X}$ (being down-right of $p$ ) and $\mathcal{Y}$ (being up-left of $p$ ). The set $\mathcal{V}$ is split now into two parts: $\mathcal{V}_{\mathcal{X}}$ consisting of those $\vec{v}_{i} \in \mathcal{V}$ for which $\vec{v}_{i}^{*}$ corresponds to a segment in $\mathcal{X}$, and a similar part $\mathcal{V}_{\mathcal{Y}}$. Notice that the $\mathcal{V}$-curve consists of several segments corresponding to $\mathcal{V}_{\mathcal{X}}$, followed by those corresponding to $\mathcal{V}_{\mathcal{Y}}$. Hence there is a vertex $p$ of the $\mathcal{V}$-curve separating $\mathcal{V}_{\mathcal{X}}$ from $\mathcal{V}_{\mathcal{Y}}$. Claim 1 now yields that $p^{\prime} \geqslant p$, so $p^{\prime} \in \mathcal{D}$, as required.

Claim 2 implies that the final set $\mathcal{F}$ is contained in $\mathcal{D}$.

4. $\mathcal{D}$ is stable, and its comfortable points are known. Recall the definitions of $r_{i}$; let $r_{i}^{\prime}$ be the ray complementary to $r_{i}$. By our definitions, the set $N(O)$ contains no points between the rays $r_{i}$ and $r_{i+1}$, as well as between $r_{i}^{\prime}$ and $r_{i+1}^{\prime}$.

Claim 3. In the set $\mathcal{D}$, all lattice points of the $\mathcal{V}$-curve are comfortable.

Proof. Let $p$ be any lattice point of the $\mathcal{V}$-curve, belonging to some segment $d_{i} d_{i+1}$. Draw the line $\ell$ containing this segment. Then $\ell \cap \mathcal{D}$ contains exactly $k_{i}+1$ lattice points, all of which lie in $N(p)$ except for $p$. Thus, exactly half of the points in $N(p) \cap \ell$ lie in $\mathcal{D}$. It remains to show that all points of $N(p)$ above $\ell$ lie in $\mathcal{D}$ (recall that all the points below $\ell$ lack this property).



Notice that each vector in $\mathcal{V}$ has one coordinate greater than $n / 2$; thus the neighborhood of $p$ contains parts of at most two segments of the $\mathcal{V}$-curve succeeding $d_{i} d_{i+1}$, as well as at most two of those preceding it.

The angles formed by these consecutive segments are obtained from those formed by $r_{j}$ and $r_{j-1}^{\prime}$ (with $i-1 \leqslant j \leqslant i+2$ ) by shifts; see the Figure below. All the points in $N(p)$ above $\ell$ which could lie outside $\mathcal{D}$ lie in shifted angles between $r_{j}, r_{j+1}$ or $r_{j}^{\prime}, r_{j-1}^{\prime}$. But those angles, restricted to $N(p)$, have no lattice points due to the above remark. The claim is proved.
<img_3487>

Proof of Claim 3

Claim 4. All the points of $\mathcal{D}$ which are not on the boundary of $D$ are crowded.

Proof. Let $p \in \mathcal{D}$ be such a point. If it is to the up-right of some point $p^{\prime}$ on the curve, then the claim is easy: the shift of $N\left(p^{\prime}\right) \cap \mathcal{D}$ by $\overrightarrow{p^{\prime} p}$ is still in $\mathcal{D}$, and $N(p)$ contains at least one more point of $\mathcal{D}$ - either below or to the left of $p$. So, we may assume that $p$ lies in a right triangle constructed on some hypothenuse $d_{i} d_{i+1}$. Notice here that $d_{i}, d_{i+1} \in N(p)$.

Draw a line $\ell \| d_{i} d_{i+1}$ through $p$, and draw a vertical line $h$ through $d_{i}$; see Figure below. Let $\mathcal{D}_{\mathrm{L}}$ and $\mathcal{D}_{\mathrm{R}}$ be the parts of $\mathcal{D}$ lying to the left and to the right of $h$, respectively (points of $\mathcal{D} \cap h$ lie in both parts).

<img_3424>

Notice that the vectors $\overrightarrow{d_{i} p}, \overrightarrow{d_{i+1} d_{i+2}}, \overrightarrow{d_{i} d_{i+1}}, \overrightarrow{d_{i-1} d_{i}}$, and $\overrightarrow{p d_{i+1}}$ are arranged in non-increasing order by slope. This means that $\mathcal{D}_{\mathrm{L}}$ shifted by $\overrightarrow{d_{i} p}$ still lies in $\mathcal{D}$, as well as $\mathcal{D}_{\mathrm{R}}$ shifted by $\overrightarrow{d_{i+1} p}$. As we have seen in the proof of Claim 3, these two shifts cover all points of $N(p)$ above $\ell$, along with those on $\ell$ to the left of $p$. Since $N(p)$ contains also $d_{i}$ and $d_{i+1}$, the point $p$ is crowded.

Thus, we have proved that $\mathcal{D}=\mathcal{F}$, and have shown that the lattice points on the $\mathcal{V}$-curve are exactly the comfortable points of $\mathcal{D}$. It remains to find their number.

Recall the definition of $\mathcal{K}_{n}$ (see Figure on the first page of the solution). Each segment $d_{i} d_{i+1}$ contains $k_{i}$ lattice points different from $d_{i}$. Taken over all $i$, these points exhaust all the lattice points in the $\mathcal{V}$-curve, except for $d_{1}$, and thus the number of lattice points on the $\mathcal{V}$-curve is $1+\sum_{i=1}^{m} k_{i}$. On the other hand, $\sum_{i=1}^{m} k_{i}$ is just the number of points in $\mathcal{K}_{n}$, so it equals $n^{2}$. Hence the answer to the problem is $n^{2}+1$.

Final answer: $n^{2}+1$