#include <bits/stdc++.h>
int a[2001];
long long dp[2001][2001];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i + 1][j + 1] =
          ((((((dp[i][j]) < (dp[i][j + 1])) ? (dp[i][j + 1]) : (dp[i][j]))) <
            (dp[i + 1][j]))
               ? (dp[i + 1][j])
               : ((((dp[i][j]) < (dp[i][j + 1])) ? (dp[i][j + 1])
                                                 : (dp[i][j])))) +
          a[i] * ((i - j) >= 0 ? (i - j) : (-(i - j)));
    }
  }
  printf("%lld", dp[n][n]);
  return 0;
}
