#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;
  x = x % p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res % p;
}
int pre[200000 + 5], suff[200000 + 5];

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  tc = 1;

  while (tc--)
  {
    int n, k,ans=0;
    cin >> n;
    int a[n],b[n];
    for (int i = 0; i < n; i++)
    {
      cin >> a[i];
    }
    int l = 0, r = n-1;
    map<int, int> mp;
    int c = n;
    while(c){
      int mx = -1;
      int in;
      for (int i = 0; i < n;i++){
        if(mp[i]==1){
          continue;
        }
        else{
          if(a[i]*abs(i-l)>mx){
            mx = a[i] * abs(i - l);
            in = i;
          }
          if(a[i]*abs(r-i)>mx){
            mx = a[i] * abs(r - i);
            in = i;
          }
        }
      }
      if(a[in]*abs(in-l)>a[in]*abs(r-in)){
        b[l] = a[in];
        l++;
      }
      else{
        b[r] = a[in];
        r--;
      }
      mp[in] = 1;
      ans += mx;
      c--;
    }
     
      cout << ans << endl;
  }

  return 0;
}