The number of nonnegative integer solutions of x₁+⋯+x_k=n is C(n+k−1,k−1), for n≥0 and k≥1. Represent n identical stars separated into k named boxes by k−1 bars; adjacent bars and end bars allow zero entries. Boxes are distinguishable, objects are not. Counting distinct tokens would instead assign each token independently, giving k^n before other constraints. Decide the model from what the objects and recipients represent, not from a familiar-looking binomial coefficient.
For positive allocations x_i≥1, put z_i=x_i−1; the remaining total is n−k, giving C(n−1,k−1) when n≥k. More general lower bounds x_i≥a_i are handled by subtracting each a_i. At least one zero is the complement of every entry positive: subtract C(n−1,k−1) from the nonnegative total. Overlapping cases such as exactly two empty boxes need a different count; subtracting each empty-box case independently double-counts their intersections.
Trace a flowchart one executed statement at a time, recording variables in a table. Distinguish assignment from a mathematical equality test; the right side of an assignment uses the old value before replacement. Record which branch executes next and which variables reset. A new outer-loop candidate may reset an inner sum without resetting the candidate itself. For a process that adds 1,3,5,… to S from zero, after m additions S=m² and the next addend is 2m+1.
A loop invariant is true before and after each iteration. The square-sum invariant holds initially at m=0 and is preserved because m²+(2m+1)=(m+1)². An invariant alone does not prove termination. To test whether an integer N≥0 is square by adding odd numbers until S≥N, S grows without bound; equivalently m increases and must reach a bound such as N. At exit, equality means square and overshoot means nonsquare. A printed value must be reached on an actual execution path; a plausible numerical pattern alone is not a trace.