#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;
struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec) is >> x;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}
template <typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N - 1>::print(t);
    cout << ", " << get<N - 1>(t);
  }
};
template <typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) { cout << get<0>(t); }
};
template <typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}
inline void print(void) { cout << '\n'; }
template <class T>
inline void print(const T &x) {
  cout << x << '\n';
}
template <class T, class... U>
inline void print(const T &x, const U &...y) {
  cout << x << " ";
  print(y...);
}
template <class T, class U>
inline bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<tuple<long long, long long, int>> a(n);
  for (int i = 0; i < (n); ++i) {
    long long t;
    cin >> t;
    a[i] = make_tuple(t, 0, i);
  }
  for (int i = 0; i < (n); ++i) {
    int idx = i;
    long long ma = 0;
    for (int j = 0; j < (n); ++j) {
      if (i == j) continue;
      long long diff1 = get<0>(a[i]) * abs(get<2>(a[i]) - j) - get<1>(a[i]);
      long long diff2 = get<0>(a[j]) * abs(get<2>(a[j]) - i) - get<1>(a[j]);
      if (diff1 + diff2 > ma) {
        idx = j;
        ma = diff1 + diff2;
      }
    }
    if (idx != i) {
      a[i] = make_tuple(get<0>(a[i]), get<0>(a[i]) * abs(get<2>(a[i]) - idx),
                        get<2>(a[i]));
      a[idx] =
          make_tuple(get<0>(a[idx]), get<0>(a[idx]) * abs(get<2>(a[idx]) - i),
                     get<2>(a[idx]));
      swap(a[i], a[idx]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans += get<0>(a[i]) * abs(get<2>(a[i]) - i);
  }
  print(ans);
  return 0;
}
