# 396. Rotate Function

F(i+1) - F(i) = sum(A) - Array.length \* A\[k-1]

```python
import sys
class Solution:
    def maxRotateFunction(self, A: List[int]) -> int:
        res = sum([i*val for i,val in enumerate(A)])
        curr = res
        n = len(A)
        s = sum(A)
        if n == 0:
            return 0
        while len(A) > 1:
            curr += s - n * A.pop()
            res = max(res,curr)
        return res
        
```
