#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  long long ans = 0;
  for (int ii = 0; ii < (int)(N); ii++) {
    long long m = 0;
    int mi, mj;
    for (int i = 0; i < (int)(N); i++) {
      for (int j = i + 1; j < N; j++) {
        m = max((long long)(A[i] + A[j]) * (j - i), m);
        if (m == (A[i] + A[j]) * (j - i)) {
          mi = i;
          mj = j;
        }
      }
    }
    if (m == 0) break;
    ans += m;
    A[mi] = 0;
    A[mj] = 0;
  }
  cout << ans;
}
