```
#define max(a, b) (a) > (b) ? (a) : (b)
int maxRotateFunction(int* A, int ASize) {
long sum, maxS, f;
int i;
for (f = i = sum = 0; i < ASize; i++) {
sum += A[i];
f += i * A[i];
}
for (i = 1, maxS = f; i < ASize; i++, maxS = max(maxS, f))
f = f + sum - ASize * A[ASize - i];
return maxS;
}
```