#include <bits/stdc++.h>
using namespace std;
void parseArray(long long* A, long long n) {
  for (long long K = 0; K < n; K++) {
    cin >> A[K];
  }
}
long long modInverse(long long a, long long b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long double dist(long double x, long double y, long double a, long double b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(long long* a, long long n) {
  for (long long k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cout << "\n";
}
const long long mod = 1000000007;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long n;
  cin >> n;
  long long a[n];
  parseArray(a, n);
  long long ans = 0;
  long long l = 0, r = n - 1;
  bool vis[n];
  memset(vis, 0, sizeof vis);
  for (int k = 0; k < n; k++) {
    long long cand = -1;
    long long pos = 0;
    for (int j = 0; j < n; j++) {
      if (vis[j]) continue;
      long long tmp = max(a[j] * abs(j - l), a[j] * abs(r - j));
      if (tmp > cand) {
        cand = tmp;
        pos = j;
      }
    }
    vis[pos] = 1;
    ans += cand;
    if (a[pos] * abs(pos - l) > a[pos] * abs(pos - r))
      l++;
    else
      r--;
  }
  cout << ans << endl;
  return 0;
}
