#include <bits/stdc++.h>
void swap(long long *a, long long *b) {
  long long c;
  c = *b;
  *b = *a;
  *a = c;
}
long long max2(long long a, long long b) { return a >= b ? a : b; }
long long min2(long long a, long long b) { return a >= b ? b : a; }
long long min3(long long a, long long b, long long c) {
  return (a <= b && a <= c) ? a : b <= c ? b : c;
}
long long max3(long long a, long long b, long long c) {
  return (a >= b && a >= c) ? a : b >= c ? b : c;
}
long long minn(long long n, long long a[n]) {
  long long b = (1LL << 60);
  for (long long i = (0); i < (n); i++) b = min2(b, a[i]);
  return b;
}
long long maxn(long long n, long long a[n]) {
  long long b = -(1LL << 60);
  for (long long i = (0); i < (n); i++) b = max2(b, a[i]);
  return b;
}
long long ABS(long long a) { return a >= 0 ? a : (-a); }
long long POW(long long a, long long b) {
  long long c = 1;
  for (long long i = (0); i < (b); i++) c *= a;
  return c;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long mod(long long n) {
  n += n < 0 ? ((-n) / 1000000007 + 1) * 1000000007 : 0;
  return n %= 1000000007;
}
int upll(const void *a, const void *b) {
  return *(long long *)a < *(long long *)b   ? -1
         : *(long long *)a > *(long long *)b ? 1
                                             : 0;
}
int downll(const void *a, const void *b) {
  return *(long long *)a < *(long long *)b   ? 1
         : *(long long *)a > *(long long *)b ? -1
                                             : 0;
}
void sortup(long long *a, int n) { qsort(a, n, sizeof(long long), upll); }
void sortdown(long long *a, int n) { qsort(a, n, sizeof(long long), downll); }
typedef struct {
  long long a, b, c;
} fr;
int cmp1(const void *p, const void *q) { return ((fr *)p)->a - ((fr *)q)->a; }
int cmp2(const void *p, const void *q) {
  if (((fr *)q)->a == ((fr *)p)->a) return ((fr *)q)->c - ((fr *)p)->c;
  return ((fr *)q)->a - ((fr *)p)->a;
}
void strsortup(fr *a, int n) { qsort(a, n, sizeof(fr), cmp1); }
void strsortdown(fr *a, int n) { qsort(a, n, sizeof(fr), cmp2); }
int main(void) {
  long long n, ans = 0;
  scanf("%lld", &n);
  fr chi[n];
  fr p[n];
  long long left = 0, right = n - 1;
  for (long long i = (0); i < (n); i++) {
    scanf("%lld", &chi[i].a);
    chi[i].b = i;
    chi[i].c = 0;
  }
  for (long long i = (0); i < (n); i++) {
    for (long long j = (0); j < (n); j++) {
      p[j].a =
          chi[j].a * max2(ABS(chi[j].b - left) - 1, ABS(chi[j].b - right) - 1);
      p[j].b = chi[j].b;
      p[j].c = chi[j].a;
    }
    strsortdown(p, n);
    for (long long j = (0); j < (n); j++) {
      if (chi[p[j].b].c == 0) {
        chi[p[j].b].c = 1;
        ans += p[j].a + chi[p[j].b].a;
        if (ABS(chi[p[j].b].b - left) > ABS(chi[p[j].b].b - right)) {
          left++;
        } else {
          right--;
        }
        break;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
