#include <bits/stdc++.h>
using namespace std;
long long binpow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
unsigned long long binpowmod(unsigned long long x, unsigned long long y,
                             unsigned long long p) {
  unsigned long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long mod_inverse(long long n, long long p) {
  return binpowmod(n, p - 2, p);
}
unsigned long long gcd(unsigned long long x, unsigned long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
bool comp(pair<int, int> x, pair<int, int> y) { return x.first < y.first; }
bool comp_pairs_by_s(pair<long long, long long> &x,
                     pair<long long, long long> &y) {
  return x.second < y.second;
}
bool isPowerOfTwo(long long x) { return x && (!(x & (x - 1))); }
class cmp {
 public:
  bool operator()(pair<int, int> A, pair<int, int> B) {
    if (abs(A.first - A.second) == abs(B.first - B.second))
      return A.first > B.first;
    return abs(A.first - A.second) < abs(B.first - B.second);
  }
};
void swap(int &x, int &y) {
  int temp = x;
  x = y;
  y = temp;
}
void solve() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (auto &it : v) cin >> it;
  int i = 0;
  int j = n - 1;
  long long ans = 0;
  while (i <= j) {
    int index;
    long long temp = INT_MIN;
    int index_used = -1;
    for (int k = 0; k < n; k++) {
      if (v[k] < 0) continue;
      if (abs(k - i) > abs(k - j)) {
        if (v[k] * abs(k - i) > temp) {
          temp = v[k] * abs(k - i);
          index = k;
          index_used = i;
        }
      } else if (abs(k - i) < abs(k - j)) {
        if (v[k] * abs(k - j) > temp) {
          temp = v[k] * abs(k - j);
          index = k;
          index_used = j;
        }
      } else {
        if (v[k] * abs(k - j) > temp) {
          temp = v[k] * abs(k - j);
          index = k;
        }
      }
    }
    if (index_used >= 0) {
      ans += v[index] * abs(index_used - index);
      v[index] = -1;
      if (index_used == i)
        i++;
      else
        j--;
    } else {
      long long temp1 = INT_MIN;
      int indexx = i;
      for (int p = 0; p < n; p++) {
        if (v[p] < 0) continue;
        if (max(v[p] * abs(p - i), v[p] * abs(p - j)) > temp1) {
          temp1 = max(v[p] * abs(p - i), v[p] * abs(p - j));
          if (v[p] * abs(p - i) >= v[p] * abs(p - j))
            indexx = i;
          else
            indexx = j;
        }
      }
      if (indexx == i) {
        ans += v[index] * abs(j - index);
        v[index] = -1;
        j--;
      } else {
        ans += v[index] * abs(i - index);
        v[index] = -1;
        i++;
      }
    }
  }
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
