#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1e9+7;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 1000000000;
const long eps = .0000000001;

void func(long long val, long long* maxval, int* nums, int* maxind, int j, int num){
    if (val > maxval[0] || (val == maxval[0] && num > nums[0])){
          maxval[1] = maxval[0];
          maxind[1] = maxind[0];
          nums[1] = nums[0];
          maxval[0] = val;
          maxind[0] = j;
          nums[0] = num;
      }else if (val > maxval[1] || (val == maxval[1] && num > nums[1])){
          maxval[1] = val;
          maxind[1] = j;
          nums[1] = num;
      }
}
int main ()
{
  prep();
  int n;
  cin >> n;
  long long arr[n];
  long long sum = 0;
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  bool moved[n] = {false};
  for (int i=0; i<n/2; i++){
      // best baby for i and for n-i
      long long maxval[2] = {-1, -1};
      int maxind[2] = {-1, -1};
      int nums[2] = {-1, -1};
      long long omaxval[2] = {-1, -1};
      int omaxind[2] = {-1, -1};
      int onums[2] = {-1, -1};
      int oind = n-i-1;
      for (int j=0; j<n; j++){
          if (moved[j]){
              continue;
          }
          long long val = abs(j-i)*arr[j];
          long long oval = abs(oind-j)*arr[j];
          func(val, maxval, nums, maxind, j, arr[j]);
          func(oval, omaxval, onums, omaxind, j, arr[j]);
      }
      //cout << maxind[0] << " " << omaxind[0] << endl;
      if (maxind[0] == omaxind[0]){
          // choose greatest
          if (maxval[0] > omaxval[0]){
              moved[maxind[0]] = true;
              sum += maxval[0];
              moved[omaxind[1]] = true;
              sum += omaxval[1];
          }else{
              moved[omaxind[0]] = true;
              sum += omaxval[0];
              moved[maxind[1]] = true;
              sum += maxval[1];
          }
      }else{
          moved[maxind[0]] = true;
          sum += maxval[0];
          moved[omaxind[0]] = true;
          sum += omaxval[0];
          
      }
  }
  if (n%2 == 1){
      for (int j=0; j<n; j++){
          if (moved[j]){
              continue;
          }
          sum += abs(j-n/2)*arr[j];
          break;
      }
  }
  cout << sum;
  return 0;
}
