```
class Solution(object):
def findMinMoves(self, machines):
"""
:type machines: List[int]
:rtype: int
"""
if not machines:
return 0
n = len(machines)
s = sum(machines)
if s % n:
return -1
avg = s / n
ans = 0
left_sum = 0
for x in machines:
delta = x - avg
ans = max(ans, -left_sum, delta + max(0, left_sum))
left_sum += delta
return ans
```