#include <bits/stdc++.h>
using namespace std;
void solve(int tc) {
  int n;
  cin >> n;
  vector<pair<long long, long long>> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort((a).begin(), (a).end());
  reverse((a).begin(), (a).end());
  vector<bool> placed(n, false);
  vector<long long> b(n, 0);
  for (int i = 0; i < n; ++i) {
    int tar = a[i].second;
    for (int j = 0; j < n; ++j) {
      if (placed[j]) continue;
      if (abs(a[i].second - j) > abs(a[i].second - tar)) tar = j;
    }
    placed[tar] = true;
    b[tar] = a[i].first * abs(a[i].second - tar);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) ans += b[i];
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  for (int tc = 1; tc <= t; ++tc) {
    solve(tc);
  }
  return 0;
}
