#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
template <class code>
inline code read(const code &a) {
  code x = 0;
  short w = 0;
  char ch = 0;
  while (!isdigit(ch)) {
    w |= ch == '-';
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return w ? -x : x;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) print(x / 10);
  putchar(x % 10 + 48);
}
long long ans = 0;
struct pp {
  long long z;
  long long wz;
} a[2005];
int n;
int abs(int x) { return x < 0 ? -x : x; }
bool cmp(pp x, pp y) {
  if (x.z != y.z)
    return x.z > y.z;
  else
    return abs(x.wz - n / 2) < (y.wz - n / 2);
}
long long l, r;
bool pd(int x) {
  if (x > n) return 0;
  return abs(a[x].wz - l) == abs(r - a[x].wz)
             ? pd(x + 1)
             : abs(a[x].wz - l) > abs(r - a[x].wz);
}
int main() {
  n = read(n);
  for (int i = 1; i <= n; i++) {
    a[i].z = read(a[i].z);
    a[i].wz = i;
  }
  sort(a + 1, a + n + 1, cmp);
  l = 1, r = n;
  for (int i = 1; i <= n; i++) {
    if (abs(a[i].wz - l) < abs(r - a[i].wz)) {
      ans += abs(r - a[i].wz) * a[i].z;
      --r;
    } else if (abs(a[i].wz - l) > abs(r - a[i].wz)) {
      ans += abs(a[i].wz - l) * a[i].z;
      ++l;
    } else if (!pd(i + 1)) {
      ans += abs(r - a[i].wz) * a[i].z;
      --r;
    } else {
      ans += abs(a[i].wz - l) * a[i].z;
      ++l;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
