1# Runtime: 170 ms (Top 20.15%) | Memory: 15 MB (Top 44.78%)2from itertools import accumulate345class Solution:6def findMinMoves(self, machines: List[int]) -> int:7n = len(machines)8summation = sum(machines)9if summation % n:10return -111avg = summation // n12left = list(accumulate(machines))13result = 014for i in range(n):15move_to_right = max(left[i] - (i + 1) * avg, 0)16move_to_left = max(17left[-1] - (left[i - 1] if i != 0 else 0) - (n - i) * avg, 018)19result = max(result, move_to_right + move_to_left)20return result