Cargo Handling (move) Title Description
Heaven and earth heartless people sentient beings, one side have difficult p plus support! After the Wenchuan earthquake, the disaster area is the most shortage of relief tents, supporting tents across the country are urgently transported to the disaster area. Suppose that there is a storage point around the Kagawa of N relief tents with circular arrangement, the number of tents per storage point is m1,m2,......,mn, and s=m1+m2+......+mn must be a multiple of n. Any number of tents can be transported to adjacent storage points at any one of the storage points.
Now we need to find a way to carry the fewest tents so that the number of tents in each storage point is the same.
For example: N=5, the number of tents per storage point is 17 9 14 16 4 respectively, we carry out the following handling:
(1) Storage point ① to the storage point ② handling 1 tents;
(2) Storage point ① to the storage point ⑤ handling 4 tents;
(3) Storage point ③ to the storage point ② handling 2 tents;
(4) Storage point ④ 4 tents to the storage point ⑤.
The total number of moving tents is 1+4+2+4=11 and can prove to be the best handling method.
Input
The 1th line is a positive integer n (n≤10000), which indicates that there are n storage points;
Row 2nd n integers (integer range) representing the number of tents in n storage points.
Output
An integer representing the minimum number of tents to be transported.
Sample input
517 9 14) 16 4
Sample output
11
Analysis: Petition Naked questions (you dare say you will not, ( ̄ˇ ̄));
Cargo Handling (move)