#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 18;
const long long Mod = 1e9 + 7;
const long long INF = 1e9 + 7;
long long a[maxn];
vector<long long> v;
bool vis[maxn];
map<int, int> p;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    v.push_back(a[i]);
  }
  long long ans = 0;
  long long l = 0, r = n - 1;
  for (long long i = 0; i < n; ++i) {
    long long mx = 0, pos = 0;
    int k = 0;
    for (long long j = 0; j < n; ++j) {
      if (vis[j]) continue;
      long long m = abs(j - l) * v[j];
      if (m > mx) {
        mx = m;
        pos = j;
        k = 0;
      }
      m = abs(r - j) * v[j];
      if (m > mx) {
        mx = m;
        pos = j;
        k = 1;
      }
    }
    vis[pos] = 1;
    if (k)
      r--;
    else
      l++;
    ans += mx;
  }
  cout << ans << endl;
  return 0;
}
