```
class Solution(object):
def findMinMoves(self, machines):
"""
:type machines: List[int]
:rtype: int
"""
total = sum(machines)
if total%len(machines)!=0:
return -1
ave = total/len(machines)
prefix = 0
res = 0
for i in range(len(machines)):
leftNeeds = max(i*ave - prefix, 0)
rightNeeds = max(prefix + machines[i] - (i+1)*ave, 0)
prefix += machines[i]
res = max(leftNeeds+rightNeeds, res)
return res
```