#include <bits/stdc++.h>
int x[2010], y[2010];
int main() {
  int a;
  scanf("%d", &a);
  for (int i = 1; i <= a; i++) scanf("%d", &x[i]);
  long long int ans = 0;
  for (int i = 0; i <= a; i++) {
    long long int sum = 0;
    for (int j = 1; j <= a; j++) y[j] = x[j];
    for (int j = 1; j <= i; j++) sum -= y[j] * j;
    for (int j = i + 1; j <= a; j++) sum += y[j] * j;
    std::sort(y + 1, y + i + 1);
    std::sort(y + i + 1, y + a + 1);
    for (int j = 1; j <= i; j++) sum += y[j] * (a + j - i);
    for (int j = i + 1; j <= a; j++) sum -= y[j] * (a - j + 1);
    ans = ans > sum ? ans : sum;
  }
  printf("%lld", ans);
}
