#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template <class T>
using vv = vector<vector<T>>;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) os << (i ? ", " : "") << vec[i];
  os << "}";
  return os;
}
ostream& operator<<(ostream& os, const vector<char>& v) {
  for (size_t i = 0; i < v.size(); ++i) os << v[i];
  return os;
}
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& rhs) {
  os << "(" << rhs.first << ", " << rhs.second << ")";
  return os;
}
int main() {
  int N;
  cin >> N;
  ;
  set<pii> s, s2;
  for (int i = 0, _i = (N); i < _i; ++i) {
    int a;
    cin >> a;
    ;
    s.insert(pii(i, a));
    s2.insert(pii(i, a));
  }
  ll ans = 0, ans2 = 0;
  for (int i = 0, _i = (N / 2); i < _i; ++i) {
    pii target;
    ll tmp = -1;
    for (const auto& e : s) {
      if (chmax(tmp, 1LL * abs(e.first - i) * e.second)) {
        target = e;
      }
    }
    42;
    s.erase(target);
    ans += tmp;
  }
  for (int i = (N - 1); i >= 0; --i) {
    if (s.empty()) break;
    pii target;
    ll tmp = -1;
    for (const auto& e : s) {
      if (chmax(tmp, 1LL * abs(e.first - i) * e.second)) {
        target = e;
      }
    }
    s.erase(target);
    ans += tmp;
  }
  for (int i = (N - 1); i >= 0; --i) {
    if (i <= N / 2) break;
    pii target;
    ll tmp = -1;
    for (const auto& e : s2) {
      if (chmax(tmp, 1LL * abs(e.first - i) * e.second)) {
        target = e;
      }
    }
    s2.erase(target);
    ans2 += tmp;
  }
  for (int i = 0, _i = (N); i < _i; ++i) {
    if (s2.empty()) break;
    pii target;
    ll tmp = -1;
    for (const auto& e : s2) {
      if (chmax(tmp, 1LL * abs(e.first - i) * e.second)) {
        target = e;
      }
    }
    s2.erase(target);
    ans2 += tmp;
  }
  cout << max(ans, ans2) << endl;
  return 0;
}
