An art student lays out ornaments in a row with weights weights[0], weights[1], ... and builds a hanging mobile from them. She repeatedly takes two neighbouring pieces (a single ornament, or a part of the mobile she has already built) and hangs them from the two ends of a new rod, which becomes one piece whose weight is their sum. She stops when everything hangs from one rod. The order of the row never changes.
A rod wobbles by the difference between the weights on its two ends, abs(left - right). Implement min_wobble(weights: list[int]) -> int: the smallest possible total wobble over all the rods.
min_wobble([1, 1, 2, 4]) # 0 (1|1) weighs 2, (2|2) weighs 4, (4|4): every rod balances
min_wobble([2, 2, 3, 1]) # 2 (2|2) and (3|1) both weigh 4, then (4|4): wobble 0 + 2 + 0
Always joining the most balanced neighbouring pair first does not work: on the second example it starts with (2|2), then joins (4|3) and (7|1), and ends up at 7. A single ornament needs no rods, so its wobble is 0.
Constraints: 1 <= len(weights) <= 80, 1 <= weights[i] <= 1000. O(n³) is fine.
Show hint
the top rod of the mobile over weights[l..r] splits it into a left part l..k and a right part k+1..r, and wobbles by abs(sum(l..k) - sum(k+1..r)), which now depends on k. So wobble[l][r] = min over k of wobble[l][k] + wobble[k+1][r] + abs(sum(l..k) - sum(k+1..r)); use prefix sums and fill by increasing interval length.