Time limit
1s
Memory limit
128 MB
Consider a round table with t legs placed at equal angular intervals on the rim. Every leg is perpendicular to the tabletop, and their lengths may differ. You may shorten legs, but you may not lengthen them.
After cutting, the table is stable exactly when the longest remaining legs surround the center of the table. If the center lies only on the boundary of their contact polygon, that is not considered stable. Not every leg has to touch the floor.
For each test case, find the minimum possible total length cut from the legs.
The input consists of several test cases. For each case, the first line contains the number of legs t (3 <= t <= 50). The next t lines each contain one leg length, given in circular order around the table.
The input ends with a line containing 0.
For each test case, output the minimum total amount that must be cut. Put one blank line between the outputs of consecutive test cases.