#include <bits/stdc++.h>
using namespace std;
const long long oo = 2e18;
template <typename T>
void db(T x) {}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long N;
  cin >> N;
  vector<pair<long long, long long>> arr;
  for (long long i = 0; i < N; i++) {
    long long n;
    cin >> n;
    arr.push_back({n, i});
  }
  for (long long x = 0; x < N; x++) {
    for (long long i = 0; i < N - 1; i++) {
      long long p1 = arr[i].first * abs(arr[i].second - i) +
                     arr[i + 1].first * abs(arr[i + 1].second - (i + 1));
      long long p2 = arr[i].first * abs(arr[i].second - (i + 1)) +
                     arr[i + 1].first * abs(arr[i + 1].second - i);
      if (p2 > p1) swap(arr[i], arr[i + 1]);
    }
  }
  long long res = 0;
  for (long long i = 0; i < N; i++) {
    res += arr[i].first * abs(arr[i].second - i);
  }
  cout << res << '\n';
  return 0;
}
