The code below is perfectly right if it runs in IntelliJ, but I got a wrong answer in leetcode.

```
public class Solution {
public static int sum;
public static int pre;
public int maxRotateFunction(int[] A) {
// int sum = 0;
// int pre = 0;
int max = Integer.MIN_VALUE;
int n = A.length;
if (n <= 1) return 0;
for (int i = 0; i < n; i++) {
sum += A[i];
pre += i * A[i];
}
if (pre > max) max = pre;
for (int i = n - 1; i >= 1; i--) {
pre = pre + sum - n * A[i];
if (pre > max) max = pre;
}
return max;
}
}
```