#include <bits/stdc++.h>
const int maxn = 2005;
int n, head, tail, ans;
int a[maxn];
bool vis[maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  head = 1, tail = n;
  while (head <= tail) {
    int maxx = -1, maxn;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] &&
          maxx < a[i] * std::max(std::abs(i - head), std::abs(i - tail))) {
        maxx = a[i] * std::max(std::abs(i - head), std::abs(i - tail));
        maxn = i;
      }
    }
    ans += maxx, vis[maxn] = 1;
    if (std::abs(maxn - head) < std::abs(maxn - tail))
      --tail;
    else
      ++head;
  }
  printf("%d", ans);
}
