#include <bits/stdc++.h>
using namespace std;
class ned {
 public:
  long long int val;
  int num, ind, imp;
  ned(long long int a, int b, int c, int d) {
    val = a;
    num = b;
    imp = c;
    ind = d;
  }
};
bool func(ned c1, ned c2) {
  if (c1.val > c2.val)
    return true;
  else if (c1.val == c2.val) {
    if (c1.imp == 2)
      return false;
    else {
      if (c1.num > c2.num) return true;
    }
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long int ans = 0;
  int l = 0, r = n - 1;
  vector<bool> vis(n, false);
  for (int i = 0; i < n; i++) {
    vector<ned> vt;
    for (int j = 0; j < n; j++) {
      if (vis[j] == false) {
        long long int f = v[j] * 1LL * abs(j - l);
        long long int b = v[j] * 1LL * abs(j - r);
        if (f > b) {
          ned t(f, v[j], 0, j);
          vt.push_back(t);
        } else if (b > f) {
          ned t(b, v[j], 1, j);
          vt.push_back(t);
        } else {
          ned t(b, v[j], 2, j);
          vt.push_back(t);
        }
      }
    }
    sort(vt.begin(), vt.end(), func);
    if (vt[0].imp == 0)
      l += 1;
    else
      r -= 1;
    ans += vt[0].val;
    vis[vt[0].ind] = true;
  }
  cout << ans << endl;
}
