\section{Sides divisible by three} \label{sec:residue-zero} \begin{theorem} For every integer \(k\geq 1\), \[ P(3k)=3k^2+3k-2. \] \end{theorem} \paragraph{Construction.} For \(k\geq 7\) the construction specifies the unmarked set \(U_k\) by placing two top cap rows, the row word \(W_k\), and two bottom cap rows in that order. Each pattern specifies the unmarked sites of its row. An ordinary row \(R_a\) uses column \(3i+1\) in every triple \(0\leq ia\). A seam row \(S_a\) is \(R_a\) with column \(3a+2\) removed. The initial word is \[ W_7 = R_4\,R_3\,R_2\,S_2\,R_1\,R_0\,S_0\,R_0\,S_1\, R_1\,R_2\,S_3\,R_3\,S_4\,R_4\,R_5\,R_6 . \] The recursion is \(W_{k+1}=R_{k-2}S_{k-2}W_k R_k\), with all patterns read at the new width. The word has \(3k-4\) rows, of which \(k-2\) are seams. The cap rows, in order from top to bottom, have no unmarked sites, all sites unmarked, columns \(1,\ldots,3k-1\) unmarked, and just column \(1\) unmarked (in zero-based coordinates). Hence \[ |U_k|=6k+2k(3k-4)-(k-2)=6k^2-3k+2. \] To certify that \(F=V(G_{3k})\setminus U_k\) is feasible, use the planar dual, with one vertex for each unit face and one for the exterior. Keep a dual edge when both endpoints of its primal edge are in \(U_k\). These are precisely the dual edges complementary to \(E(F)\). If \(E(F)\) contained a cycle, the faces inside it would have no path to the exterior in this dual. The construction proves dual connectivity by maintaining paths from the interior face rows to a distinguished face adjacent to the exterior. The path invariant uses a restricted dual graph whose edges persist under widening. It is checked at \(k=7\). In the step from \(k\) to \(k+1\), the persistent paths are translated two rows down; a bridge joins the translated distinguished face to the new one. The new top and appended interior rows attach to the translated interior, and the new right slab has paths to the new distinguished face. The two outer face rows are handled by the boundary attachment lemmas. This gives an acyclic \(E(F)\) with \(9k^2-|U_k|\) marks. The count is \texttt{uResidueZero\_card}; the invariant and its acyclicity consequence are \texttt{persistentResidueZeroCertificate} and \texttt{forced\_compl\_uResidueZero\_isAcyclic} in the \texttt{ResidueZero} construction files. For \(1\leq k<7\) the individual constructions are collected in \nolinkurl{matchingDiagonalConstructions_residueZeroFinite}. \paragraph{Local upper certificate.} Let \(n=3k\) with \(k\geq4\), and let \(E(F)\) be a forest. Orient its edges toward one root per component, choosing the upper-left corner as the root of its component. A \emph{star} records the mark bit of its central vertex, the four neighbour bits (zero off the board), and the direction of its outgoing forced edge, or a root symbol if there is no outgoing edge. A \emph{patch} records the nine mark bits in a \(3\times3\) window (Figure~\ref{fig:local-records}). A star or patch is \emph{physical} if it is read at a specified location from the actual marked set and, for a star, the chosen forest orientation. The certificate also checks candidate records satisfying local tests, without requiring that each candidate extend to a whole forest. A physical star cannot have marked neighbours in consecutive compass directions: their marks would force a unit cycle. Its outgoing direction, if present, must use a forced edge. Similarly, a physical patch cannot contain any of the thirteen forbidden submasks in \texttt{maskOK}: each covers all edges of a cycle inside the patch. \begin{figure}[htbp] \centering \begin{tikzpicture}[x=6mm,y=-6mm,every node/.style={font=\small}] \node at (1,-.7) {(a) Star}; \node at (4.6,-.7) {(b) Patch}; \node at (11.1,-.7) {(c) Tile word}; \draw[gray!60] (1,0)--(1,2) (0,1)--(2,1); \foreach \x/\y in {1/0,1/1,2/1,1/2} \filldraw[fill=white] (\x,\y) circle (1.6pt); \fill (0,1) circle (2pt); \draw[->,thick,shorten <=3pt,shorten >=3pt] (1,1)--(0,1); \begin{scope}[shift={(3.6,0)}] \foreach \i in {0,1,2} \draw[gray!60] (\i,0)--(\i,2) (0,\i)--(2,\i); \foreach \x in {0,1,2} \foreach \y in {0,1,2} { \pgfmathtruncatemacro{\sitebit}{3*\y+\x} \filldraw[fill=white] (\x,\y) circle (1.6pt); \node[anchor=north west,inner sep=2pt] at (\x,\y) {\scriptsize \sitebit}; } \fill (0,1) circle (2pt) (0,2) circle (2pt); \end{scope} \foreach \x/\m in {7.1/64,10.1/72,13.1/72} { \draw[gray!65] (\x-.5,-.35) rectangle ++(2.8,2.75); \foreach \i in {0,1,2} \draw[gray!60] (\x+\i,0)--(\x+\i,2) (\x,\i)--(\x+2,\i); \foreach \i in {0,1,2} \foreach \j in {0,1,2} \filldraw[fill=white] (\x+\i,\j) circle (1.6pt); \fill (\x,2) circle (2pt); \ifnum\m=72\relax \fill (\x,1) circle (2pt); \fi \node at (\x+1,2.9) {\(\m\)}; } \end{tikzpicture} \caption{Local records. Filled circles are marked. (a) The central vertex points west along a forced edge. (b) The patch at the same location agrees with the star on their five shared marks or blanks. Its marked positions \(3\) and \(6\) give mask \(2^3+2^6=72\). (c) Patch windows may overlap; the tiles here are disjoint. Read their masks from left to right to obtain the tile word \(64,72,72\).} \label{fig:local-records} \end{figure} The certificate assigns integer charges to stars and patches, summed over the eight symmetries of the square. A star charge includes a normalization term, a root term, the objective term \(-\lambda\) times its mark bit per symmetry, and signed incidence terms. A patch charge contains a normalization term and signed incidence terms. There are three types of matching data: the marks and arrow on a grid edge read from its two ends; the mark pattern at a star restricted to a patch that contains it; and the mark bits in the common strip of two adjacent patches. In each case the two readings of the same data carry opposite charges. Thus their sums vanish on the physical grid, separately in each symmetry. Root charges are nonpositive. Let \(B(n)\) be the normalization budget in one view plus the fixed allowance from the chosen corner. At scale \(\lambda=4373984\), the sums \(S\) and \(T\) of star and patch charges satisfy \[ 0\leq S+T\leq 8 B(n)-8\lambda |F|. \] Here are the finite and geometric obligations behind this inequality. \begin{enumerate} \item The eight-view charge is nonnegative at every admissible star and patch on sides \(12,15,18,21\). At each star site the replay ranges over the two values of the central mark bit, \(16\) neighbour masks and \(5\) direction symbols; at each patch origin it ranges over all \(512\) masks. The admissibility tests above determine the entries to check. \item On side \(21+3j\), \(j\geq0\), star and patch locations can be represented at side \(21\) without changing any charge lookup or admissibility test. In each axis the representative preserves the distance to the nearer end in the six-position boundary bands and the residue modulo three in the interior. The argument applies to both the site square and the square of patch origins: it preserves the reflected labels, the nearby incidence queries and the off-board sentinel. \item The incidence cancellations and the corner bound hold on the original board. The normalization budget is computed there as well. Adding three positions to an axis inserts one of each interior phase in the label sum; taking the product of the two axis sums gives a quadratic in \(j\). Its three coefficients give \[ B(21+3j)/\lambda=166+45j+3j^2 . \] The direct budgets at \(12,15,18\), divided by \(\lambda\), are \(58,88,124\), respectively. \end{enumerate} In Lean, \texttt{starChecks} and \texttt{patchChecks} perform the local replays; \texttt{star\_nonneg} and \texttt{patch\_nonneg} use the transport. The physical inequality uses \nolinkurl{physical_marginals_zero} and \nolinkurl{cancellation_of_marginals}. The budget identity is \texttt{budget\_eq\_score}. Dividing by \(8\lambda\) gives the required upper bound throughout \(k\geq4\). \paragraph{The three smaller upper bounds.} The \(3\times3\) maximum is \(4\) (\nolinkurl{maxPreserved_three_three}). At side \(6\), tile the board by four disjoint \(3\times3\) patches; the admissible-mask check bounds each by four marks. At side \(9\), a Boolean certificate excludes a set of \(35\) marks. The clauses count mark bits and require an edge with both endpoints unmarked on each listed cycle. The list includes rectangles and additional perimeters checked to be simple grid cycles. Every forest with \(35\) marks would give a satisfying assignment; the LRAT replay proves unsatisfiability. These proofs are \texttt{ResidueZero.maxPreserved\_six} and \texttt{ResidueZero.Nine.maximum\_eq}. With the lower witnesses, the final equality is \texttt{ResidueZero.maxPreserved\_three\_mul}. \section{Sides congruent to one modulo three} \label{sec:residue-one} \begin{theorem} For \(k\geq1\), \[ P(3k+1)=C(k),\qquad C(k)=3k^2+5k+\max\!\left\{0,\left\lfloor\frac{3k-13}{10} \right\rfloor\right\}. \] Also \(P(1)=1\). \end{theorem} \paragraph{The comb construction.} For \(k\geq5\), put \(n=3k+1\) and \(R=n-8\), with rows and columns numbered from zero. Mark the first and last rows in full and mark columns \(0,3,\ldots,3k\) in rows \(2,\ldots,R+1\). Rows \(R+2,\ldots,R+5\) are given by a word of four-bit column masks specifying marked sites; all remaining sites are unmarked. A frontier sweep keeps the component labels of the active ports. Every new edge is inserted only between distinct components, and ports that are retired disappear from the frontier while their edges remain in the graph. The physical sweep includes the fixed comb and both boundary rows and proves that the resulting forest contains all of \(E(F)\). Figure~\ref{fig:comb} shows the marks at the smallest width of the uniform construction. \begin{figure}[htbp] \centering \begin{tikzpicture}[x=2.4mm,y=-2.4mm] \fill[gray!18] (-.5,9.5) rectangle (15.5,13.5); \drawmarkgrid{16}{ 1111111111111111,0000000000000000, 1001001001001001,1001001001001001, 1001001001001001,1001001001001001, 1001001001001001,1001001001001001, 1001001001001001,1001001001001001, 1001001001001001,1001000000000001, 1000010111110001,0010010000000100, 0000000000000000,1111111111111111 } \node[anchor=west] at (16,11.5) {\small Four-row cap}; \end{tikzpicture} \caption{The \(100\) marked vertices in the comb on side \(16\).} \label{fig:comb} \end{figure} In each mask, bits \(0,1,2,3\), from least to most significant, mark rows \(R+2,R+3,R+4,R+5\), respectively. Start with mask \(7\) and repeat the following \(30\)-column block from left to right: \[ \begin{gathered} 0,8,3,0,12,1,0,14,0,2,8,1,4,4,5,\\ 4,4,1,8,2,0,14,0,1,12,0,3,8,0,7 . \end{gathered} \] This block returns to the same frontier state and adds \(33\) marks. Writing \(k=10q+r\) with \(3\leq r\leq12\), use \(q\) blocks and append the length-\(3r\) word \nolinkurl{CombWord.ending}\((r)\) from \href{https://github.com/map9959/grid-graphs/blob/6fc87a38777650b7d092b2f0f2fa8a786d3c5db8/lean/GridGraphs/Constructions/CombWord.lean#L50-L61}{the table of ten endings}. The ending has \(3r+\lfloor(3r+7)/10\rfloor\) marks, and the first column has three. Thus the word has length \(n\) and its mark count, together with the fixed part, is \[ 2n+R(k+1)+3k+3+\left\lfloor\frac{3k+7}{10}\right\rfloor=C(k). \] The word calculation is \texttt{CombWord.exists\_cap}; its physical interpretation and score are assembled in \texttt{squareMaskScore\_comb}. The small lower bounds are included in \texttt{squareScore\_lower\_residue\_one}. \paragraph{Upper bound with a pitch line.} A pitch row has marks at exactly the columns divisible by three; a pitch column is the transpose. Fix a pitch row with \(k\geq5\). On each side its bonus \(b\) counts marks strictly on that side, less \(k+1\) per row. Cut just above the pitch row when it has a predecessor. The \(k+1\) vertical edges above its marks are the \emph{spokes}; their upper and lower endpoints are the respective caps' terminals, or teeth. Only spokes are forced across the cut: a mark between teeth in the preceding row would force a unit-square cycle with the nearest pitch-row mark. In each cap, two terminals belong to the same class if they are joined by a forced path in that cap. If there are \(c_+\) and \(c_-\) classes, the two join ranks are \(k+1-c_+\) and \(k+1-c_-\). Cut the spokes in a spanning tree extending the forced forest. Each of the \(k+2\) resulting components contains a spoke endpoint, and every terminal class stays within one component. Thus \(c_++c_-\geq k+2\), so the ranks sum to at most \(k\). If the pitch row is the top row, the upper cap is absent and has rank and bonus zero. The lower cap has at least one terminal class, so its rank is at most \(k\). The cap certificate bounds the bonus \(b\) in terms of the join rank \(j\): \[ 10b-7j\leq 3k-13\quad (j0\) throughout the tail, so integrality gives \(|F|\leq C(k)\). The dual checks are \texttt{verified58} and \texttt{verified61} in \texttt{NoPitch.Dual}. The physical row assembly uses \nolinkurl{upper_of_face_overlaps}, \nolinkurl{face_patch_tail} and \nolinkurl{face_line_tail}. \nolinkurl{maxPreserved_residue_one_tail} combines this with the pitch branch and the lower witness. \paragraph{Finite widths and conclusion.} The small cases through side \(13\) give the five values in Theorem~\ref{thm:square}. For sides \(19,22,25,52\), the no-pitch branch uses individual physical charts and finite dual replays, with the uniform pitch bound covering the other branch. In these finite replays the weighted bound, including the allowance for any positive column residual, is strictly below \(C(k)+1\). The remaining sides \(16,28,31,34,37,40,43,46,49,55\) use unrestricted finite stencils in \texttt{FiniteOne}. They sum maxima over local star and patch data with cancelling incidence charges; at side \(43\) three stencils cover the cases obtained by splitting at seven marks in each of the symmetry orbits of \((6,9)\) and \((9,15)\). Once the first orbit has at least eight marks, the second count is unnecessary. This exhausts the residue-one sides below \(58\). The complete case split is \texttt{GridGraphs.maxPreserved\_residue\_one}.