#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  vector<long long> big(n), las(n);
  for (int i = 0; i < n; i++) {
    big[i] = v[i] * i;
    las[i] = v[i] * (n - 1 - i);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long a = *max_element(big.begin(), big.end());
    long long b = *max_element(las.begin(), las.end());
    if (a >= b) {
      ans += a;
      int flag = 0;
      for (int i = 0; i < n; i++) {
        if (big[i] == a && flag == 0) {
          big[i] = INT_MIN;
          las[i] = INT_MIN;
          flag = 1;
        } else {
          big[i] -= v[i];
        }
      }
    } else {
      ans += b;
      int flag = 0;
      for (int i = 0; i < n; i++) {
        if (las[i] == b && flag == 0) {
          las[i] = INT_MIN;
          big[i] = INT_MIN;
          flag = 1;
        } else {
          las[i] -= v[i];
        }
      }
    }
  }
  cout << ans << endl;
}
