Company: Amazon
Difficulty: easy
Amazon has several warehouses that store piles of boxes containing goods to be shipped. In one such warehouse there are n piles numbered 1, 2, ..., n , where the i -th pile holds boxes[i] boxes. To even out the distribution of boxes, the caretaker may perform the following operation any number of times (possibly zero): Choose two distinct piles i and j ( 1 <= i, j <= n ) such that boxes[i] > 0 . Move one box from pile i to pile j : increment boxes[j] by 1 and decrement boxes[i] by 1 . Let d be the smallest value of (maximum pile size − minimum pile size) that can be reached by any sequence of such operations. Report the minimum number of operations needed to reach a configuration whose maximum-minus-minimum difference equals d . Input Format The first line contains a single integer n , the number of piles. Each of the next n lines contains a single integer; the i -th of them is boxes[i] . Output Format Print a single integer: the minimum number of operations required to reach