#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
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;
}
int n, a[2020];
pair<pair<long long, long long>, int> p[2020];
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[i] = {{a[i] + max(n - i - 1, i), a[i]}, i};
  }
  sort(p, p + n, greater<pair<pair<long long, long long>, int>>());
  int l = 0, r = n - 1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int j = p[i].second;
    if (j - l == r - j) {
      i++;
      if (i == n) {
        ans += a[j] * (r - j);
        break;
      }
      int jj = p[i].second;
      if (jj - l > r - jj) {
        ans += a[jj] * (jj - l);
        l++;
      } else {
        ans += a[jj] * (r - jj);
        r--;
      }
    }
    if (j - l > r - j) {
      ans += a[j] * (j - l);
      l++;
    } else {
      ans += a[j] * (r - j);
      r--;
    }
  }
  cout << ans << endl;
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
