#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
long long mod(long long x, long long md) { return ((x % md) + md) % md; }
class Mint {
 public:
  static long long md;
  long long x;
  Mint(long long _x) { x = mod(_x, md); }
  Mint(const Mint &y) { x = mod(y.x, md); }
};
void MintMyExgcd(long long a, long long b, long long &x, long long &y) {
  long long md = Mint::md;
  if (b == 0) {
    y = 0;
    x = 1;
    return;
  }
  MintMyExgcd(b, a % b, x, y);
  long long t = y;
  y = mod(x - (a / b) * y, md);
  x = t;
}
long long MintNY(long long x) {
  if (x == 0) {
    return 1;
  }
  long long md = Mint::md;
  long long a, b;
  MintMyExgcd(x, md, a, b);
  while (a < 0) {
    a += md;
  }
  return a;
}
Mint operator+(Mint a, Mint b) { return Mint(mod(a.x + b.x, Mint::md)); }
Mint operator-(Mint a, Mint b) { return Mint(mod(a.x - b.x, Mint::md)); }
Mint operator*(Mint a, Mint b) { return Mint(mod(a.x * b.x, Mint::md)); }
Mint operator/(Mint a, Mint b) {
  Mint c = Mint(MintNY(b.x));
  return Mint(mod(a.x * c.x, Mint::md));
}
Mint operator-(Mint a) { return Mint(-a.x); }
bool operator==(Mint a, Mint b) { return a.x == b.x; }
bool operator!=(Mint a, Mint b) { return a.x != b.x; }
bool operator>(Mint a, Mint b) { return a.x > b.x; }
bool operator<(Mint a, Mint b) { return a.x < b.x; }
bool operator>=(Mint a, Mint b) { return a.x >= b.x; }
bool operator<=(Mint a, Mint b) { return a.x <= b.x; }
void operator+=(Mint &a, Mint b) { a = a + b; }
void operator-=(Mint &a, Mint b) { a = a - b; }
void operator*=(Mint &a, Mint b) { a = a * b; }
void operator/=(Mint &a, Mint b) { a = a / b; }
ostream &operator<<(ostream &out, Mint a) {
  out << a.x;
  return out;
}
istream &operator>>(istream &in, Mint &a) {
  in >> a.x;
  return in;
}
Mint factorial(long long n) {
  if (n == 0) {
    return Mint(1);
  }
  Mint res = 1;
  for (long long i = 1; i <= n; ++i) {
    res *= i;
  }
  return res;
}
Mint multiRange(long long s, long long t) {
  Mint res = 1;
  for (long long i = s; i <= t; ++i) {
    res *= i;
  }
  return res;
}
Mint getC(long long n, long long k) {
  if (n - k < k) {
    return getC(n, n - k);
  }
  return multiRange(n - k + 1, n) / factorial(k);
}
Mint getA(long long n, long long k) { return multiRange(n - k + 1, n); }
Mint countNonNegativeDivision(long long n, long long k) {
  return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(long long n, long long k) {
  if (n < k) {
    return 0;
  }
  if (k <= 0) {
    return 0;
  }
  return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, long long b) {
  Mint res = 1;
  while (b > 0) {
    if (b % 2) {
      res *= a;
    }
    a *= a;
    b /= 2;
  }
  return res;
}
long long Mint::md = 1000000007;
int n;
long long *a;
class Child {
 public:
  int a, idx;
  Child(int _a, int _idx) : a(_a), idx(_idx) {}
};
bool cmp(const Child &a, const Child &b) {
  return (a.a > b.a) || (a.a == b.a && a.idx < b.idx);
}
int main() {
  scanf("%d", &n);
  a = new long long[n];
  vector<Child> vc;
  vc.clear();
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &a[i]);
    vc.push_back(Child(a[i], i));
  }
  sort(vc.begin(), vc.end(), cmp);
  int lc = 0, rc = n - 1;
  long long res = 0;
  long long **f = new long long *[n + 1];
  for (int i = 0; i <= n; ++i) {
    f[i] = new long long[n + 1];
    for (int j = 0; j <= n; ++j) {
      f[i][j] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    int aa = vc[i - 1].a;
    int idx = vc[i - 1].idx;
    for (int j = 0; j < i; ++j) {
      int rightIdx = n - i + j;
      f[i][j] =
          f[i - 1][j] + (long long)(abs(rightIdx - idx)) * (long long)(aa);
      if (j > 0) {
        f[i][j] =
            max(f[i][j], f[i - 1][j - 1] +
                             (long long)(abs(idx - (j - 1))) * (long long)(aa));
      }
    }
    f[i][i] = 0;
    for (int j = 0; j < i; ++j) {
      f[i][i] = max(f[i][i],
                    f[i - 1][j] + (long long)(abs(idx - j)) * (long long)(aa));
    }
  }
  cout << f[n][n] << endl;
  return 0;
}
