#include <bits/stdc++.h>
using namespace std;
template <class T>
class BIT {
 public:
  int BIT_size;
  vector<T> BIT_array;
  BIT(int BIT_size) {
    this->BIT_size = BIT_size;
    BIT_array = vector<T>(BIT_size + 1);
    fill(BIT_array.begin(), BIT_array.end(), 0);
  }
  void BIT_update(int i, T d) {
    for (; i <= BIT_size; i += (i & -i)) {
      BIT_array[i] += d;
    }
  }
  T BIT_sum(int i) {
    T BIT_sum_result = 0;
    for (; i > 0; i -= (i & -i)) {
      BIT_sum_result += BIT_array[i];
    }
    return BIT_sum_result;
  }
};
long long pow(long long a, long long b, long long m) {
  a %= m;
  long long result = 1;
  while (b > 0) {
    if (b & 1) {
      result = result * a % m;
    }
    a = a * a % m;
    b /= 2;
  }
  return result;
}
int main() {
  int n;
  cin >> n;
  int v[n + 1];
  map<int, vector<int>> m;
  vector<int> rank;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    rank.push_back(v[i]);
    m[v[i]].push_back(i);
  }
  int clock = n;
  int l = 1, r = n;
  long long solution = 0;
  while ((clock--) - 0) {
    int utility = 0, state, di, dj, X;
    for (int i = 0; i < rank.size(); i++) {
      int x = rank[i];
      int len = m[rank[i]].size();
      for (int j = 0; j < len; j++) {
        if (abs(m[rank[i]][j] - l) > abs(m[rank[i]][j] - r)) {
          if (x * abs(m[rank[i]][j] - l) > utility) {
            state = 0;
            utility = x * abs(m[rank[i]][j] - l);
            di = i;
            dj = j;
            X = x;
          }
        } else {
          if (x * abs(m[rank[i]][j] - r) > utility) {
            state = 1;
            utility = x * abs(m[rank[i]][j] - r);
            di = i;
            dj = j;
            X = x;
          }
        }
      }
    }
    solution += utility;
    if (clock == 0) continue;
    if (state == 0) l++;
    if (state == 1) r--;
    m[X].erase(m[X].begin() + dj);
    rank.erase(rank.begin() + di);
  }
  cout << solution << "\n";
}
