```
class Solution(object):
def maxRotateFunction(self, A):
tot = sum(A)
res = prev = sum([i*v for i,v in enumerate(A)])
for i in range(len(A)):
prev += tot - A[~i]*len(A)
res = max(res,prev)
return res
```