got idea from:

https://discuss.leetcode.com/topic/71764/c-solution

```
class Solution {
public:
int maxRotateFunction(vector<int>& A) {
int sum = 0, ans = 0, len = A.size();
for(int i = 0; i < len; i++)
{
sum += A[i];
ans += i*A[i];
}
int val = ans;
for(int i = len-1; i > 0; i--)
{
val += sum - len*A[i];
ans = max(ans, val);
}
return ans;
}
};
```