#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  vector<long long> vec(n);
  for (long long i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  long long lo = 0, hi = n - 1;
  set<long long> s;
  long long sum = 0;
  for (long long j = 0; j < n; ++j) {
    long long max = INT_MIN;
    long long temp;
    for (long long i = 0; i < n; ++i) {
      if (s.find(i) == s.end()) {
        long long temp1 = vec[i] * abs(hi - i);
        long long temp2 = vec[i] * abs(lo - i);
        if (temp1 > temp2) {
          if (temp1 > max) {
            max = temp1;
            temp = i;
          }
        } else {
          if (temp2 > max) {
            max = temp2;
            temp = i;
          }
        }
      }
    }
    sum += max;
    s.insert(temp);
    if (abs(hi - temp) > abs(lo - temp)) {
      hi--;
      hi = std::max(0ll, hi);
    } else {
      lo++;
      lo = std::min(n - 1, lo);
    }
  }
  cout << sum << "\n";
}
