#include <bits/stdc++.h>
using namespace std;
struct node {
  long long val, pos;
} a[200000 + 10];
bool vis[100000 + 10];
long long b[100000 + 10];
long long res = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = (1); i < (n + 1); i++) {
    cin >> a[i].val;
    a[i].pos = i;
    b[i] = a[i].val;
  }
  long long l = 1, r = n;
  for (long long i = (1); i < (n + 1); i++) {
    long long ans = 0;
    for (long long j = (1); j < (n + 1); j++) {
      if (vis[j]) continue;
      if (i % 2 == 1) {
        ans = max(ans, 1ll * abs(j - l) * b[j]);
      } else {
        ans = max(ans, 1ll * abs(j - r) * b[j]);
      }
    }
    for (long long j = (1); j < (n + 1); j++) {
      if (vis[j]) continue;
      if (i % 2 == 1 && 1ll * abs(j - l) * b[j] == ans) {
        vis[j] = true;
        l++;
        break;
      }
      if (i % 2 == 0 && 1ll * abs(j - r) * b[j] == ans) {
        vis[j] = true;
        r--;
        break;
      }
    }
    res += ans;
  }
  cout << res << "\n";
  return 0;
}
