class Solution(object):
    def maxRotateFunction(self, A):
        sum1,n=sum(A),len(A)
        if n==0:
            return 0
        max_index=temp=sum (A[i]*i for i in range(n))
        for i in range(n-1,0,-1):
            temp=temp+sum1-n*A[i]
            max_index=max(max_index,temp)
        return max_index
s=Solution()
A=[4,3,2,6]
print(s.maxRotateFunction(A))
O(N)的方法：
https://leetcode.com/problems/rotate-function/discuss/87853/Java-O(n)-solution-with-explanation
"""
class Solution(object):
    def maxRotateFunction(self, A):
        nums,n=[],len(A)
        number=range(n)
        nums.append(A.copy())
        for i in range(n-1):
            A.insert(0,A.pop())
            nums.append(A.copy())
        res=-float("inf")
        for num in nums:
            res=max(res,sum(num[j]*number[j] for j in range(n)))
        return res
        
        
class Solution(object):
    def maxRotateFunction(self, A):
        max_index,n=-float("inf"),len(A)
        if n==0:
            return 0
        start=0
        while start<n:
            num=list(range(start,n,1))+list(range(start))
            temp=sum(num[i]*A[i] for i in range(n))
            max_index=max(max_index,temp)
            start+=1
        return max_index
"""