#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int INF = 1e18;
long long int po(long long int a, long long int b) {
  long long int re = 1;
  while (b) {
    if (b % 2 == 1) {
      re = (re * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return re;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  while (test--) {
    int n;
    cin >> n;
    long long int a[n];
    int p1 = 0, p2 = n - 1, d = 0, in;
    long long int m = 0, b, ans = 0;
    bool c[n];
    for (int i = (0); i < (n); i++) {
      c[i] = 1;
      cin >> a[i];
    }
    for (int i = (0); i < (n); i++) {
      for (int j = (0); j < (n); j++) {
        if (c[j]) {
          b = a[j] * (p2 - j);
          if (b > m) {
            m = b;
            d = 1;
            in = j;
          }
          b = a[j] * (j - p1);
          if (b > m) {
            m = b;
            d = -1;
            in = j;
          }
        }
      }
      c[in] = 0;
      ans += m;
      if (d == 1) p2--;
      if (d == -1) p1++;
      m = 0;
      d = 0;
    }
    cout << ans;
  }
  return 0;
}
