# Edit Town and Simoleons 2: Solution ## Algorithms and Contributions Codex (GPT-6) provides the adjacent-averaging potential proof, batched coefficient formulas, implementations, and verification. The [reference](std.cpp) scans coefficient tails backward. The [forward batch method](solution-alternative-forward.en.md) and its [program](alternative-forward.cpp) maintain each target member’s wealth, trading more time for less preprocessing space. ## Personal Wealth and the Objective Let $k=p_1$ and $a=m_1/k$ . Splitting an initial household gives each resident its per-capita wealth. Merging a group and splitting it again replaces their personal wealth by its mean. A departing resident does not change the per-capita wealth of those left behind, so this personal-wealth model describes every edit. Reuniting all target members gives a household whose wealth is the sum over these fixed $k$ people. Arbitrarily many temporary households are allowed. ## 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. **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 $x