#include <bits/stdc++.h>
using namespace std::chrono;
using namespace std;
const long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  long long int b[n];
  for (int i = 0; i < n; ++i) b[i] = -1;
  int i = 0, j = n - 1;
  long long int sum = 0;
  vector<int> vis(n, 0);
  for (int k = 0; k < n; ++k) {
    long long int mx = -1;
    int ind;
    bool left = 0;
    for (int l = 0; l < n; ++l) {
      if (vis[l]) continue;
      long long int x = l - i;
      long long int y = j - l;
      if (a[l] * x > mx) {
        mx = a[l] * x;
        ind = l;
        left = 1;
      } else if (a[l] * y > mx) {
        mx = a[l] * y;
        ind = l;
        left = 0;
      }
    }
    sum += mx;
    if (left) {
      b[i] = a[ind];
      vis[ind] = 1;
      i++;
    } else {
      b[j] = a[ind];
      vis[ind] = 1;
      j--;
    }
  }
  cout << sum;
}
