#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
long long int ar[Max];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int ans = 0;
  long long int n;
  cin >> n;
  set<int> st;
  for (int i = 1; i <= n; i++) {
    cin >> ar[i];
    st.insert(i);
  }
  vector<pair<long long int, long long int> > vec;
  set<int> ache = st;
  while (ache.size()) {
    bool f = 0;
    vec.clear();
    for (int i : ache) {
      long long int x = *st.begin();
      long long int y = *st.rbegin();
      if (abs(x - i) > abs(y - i)) {
        vec.push_back({abs(x - i) * ar[i], i});
      } else {
        vec.push_back({abs(y - i) * ar[i], i});
      }
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    for (pair<long long int, long long int> x : vec) {
      int l = *st.begin();
      int r = *st.rbegin();
      if (abs(l - x.second) * ar[x.second] == x.first) {
        ans += abs(l - x.second) * ar[x.second];
        st.erase(l);
        ache.erase(x.second);
        f = 1;
      } else if (abs(r - x.second) * ar[x.second] == x.first) {
        ans += abs(r - x.second) * ar[x.second];
        st.erase(r);
        ache.erase(x.second);
        f = 1;
      } else {
        break;
      }
    }
    if (!f) {
      cout << ache.size() << endl;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
