# Edit Town and Simoleons 5: Solution Codex (GPT-6) provides the fixed-position construction, optimality proof, batched formulas, implementations, and verification. ## Personal Wealth and the Averaging Grid Let $k=p_1$ and $a=m_1/k$ . Define each resident's personal wealth as the mean of their household. A departing person leaves the source's remaining mean unchanged. Joining another household averages the wealth of the mover and all destination residents. Thus every legal move is a complete average of a subset of people. First relax the position limit to obtain an upper bound for all averaging operations. Then construct a sequence attaining that bound within the fixed positions. ## An Upper Bound for Every Editing Sequence This argument permits unequal current wealth among target members, so it applies to intermediate states as well. Sort everyone by nondecreasing wealth, labeling targets $T$ and outsiders $O$ . Whenever adjacent labels are $TO$ , average those two values and exchange their positions in the sorted list. Their values are equal afterward, so the list remains sorted. Continue until all $O$ labels precede all $T$ labels. Let $\Phi$ be the resulting target sum. **The choice of operations does not affect the result.** Each operation removes one label inversion. Two simultaneously available $TO$ pairs cannot overlap, so their operations commute. Induction on the number of inversions gives the same final wealth vector for every execution order. **Each operation does not decrease target wealth.** The target in a pair is no richer than the outsider. Thus $\Phi$ is at least the current target sum, and it is reachable in finitely many edits when positions are unrestricted. **No pairwise average increases $\Phi$ .** Fix the initial wealth ordering. The operations are then a fixed sequence of adjacent averaging matrices, making $\Phi$ linear in the initial coordinates. At the end, the target-sum coefficients in sorted order are $$0,0,\ldots,0,1,1,\ldots,1.$$ Propagating these coefficients backward averages adjacent coefficients at each step, preserving their nondecreasing order. A richer initial coordinate therefore has a coefficient at least as large as a poorer coordinate. Now continuously bring any two values $xm_1p_i$ using 64-bit products, then compare against at most three existing groups using $m_i p_{\mathrm{rep}}=m_{\mathrm{rep}}p_i$ . No million-element sort or floating-point comparison is needed. Store each group's total count and one initial representative's $p_{\mathrm{rep}},m_{\mathrm{rep}}$ . Compute the mean as $m_{\mathrm{rep}}/p_{\mathrm{rep}}$ . Do not invert the aggregated population: it may be a multiple of $P$ . Initial household populations are at most one million and therefore invertible. Use 64-bit total counts and keep the full exponent $s$ . The binomial recurrence divides only by $1,\ldots,k-1