#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (auto& itr : a) {
    int tmp;
    std::cin >> tmp;
    itr = tmp;
  }
  int l = 0;
  int r = n - 1;
  std::unordered_set<int> trash;
  int sum = 0;
  for (int k = 0; k < n; ++k) {
    bool isL = false;
    int index = 0;
    int max = 0;
    for (int i = 0; i < n; ++i) {
      if (trash.find(i) != trash.end()) continue;
      int lvalue = std::abs(i - l);
      int rvalue = std::abs(r - i);
      int iMax = a[i] * std::max(lvalue, rvalue);
      if (max <= iMax) {
        index = i;
        max = iMax;
        isL = lvalue > rvalue;
      }
    }
    sum += max;
    trash.emplace(index);
    if (isL) {
      ++l;
    } else {
      --r;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}
