Load balancing
In a multiprocessor system, processors are connected in a sequential chain, numbered from 1 to n. Each processor, i, has a certain number of tasks, denoted as t_i. The system is considered balanced when each processor has an equal number of tasks. Load balancing is achieved through rounds, where in each round, a processor can transfer at most one task to each of its neighboring processors. The neighbors of processor i are processors i-1 and i+1, with the first and last processors having only one neighbor each. Your task is to determine the minimum number of rounds required to balance the system.
Input
The first line of input contains an integer n, representing the number of processors (1 ≤ n ≤ 5000). The second line contains a sequence t, which is of length n and consists of integers ranging from 0 to 50000 inclusive.
Output
Output the minimum number of rounds needed to balance the system. If the total number of tasks in sequence t is not divisible by n, then balancing is impossible, and you should output -1.