#include <iostream>
#include <deque>

#include <algorithm>

using namespace std;

int main(){
  int N;
  long A[2001];
  
  cin >> N;
  for(int i=1;i<=N;i++){
  	cin >> A[i];  
  }
  
  int person[2001] = {0};
  int pos[2001] = {0};
  
  deque<pair<long,pair<int,int>>> score;
  
  for(int i=1; i<=N; i++){
  	for(int pos=1; pos<=N; pos++){
		score.push_back(make_pair(A[i]*abs(i-pos),make_pair(i,pos)));
    }
  }
  sort(score.begin(),score.end(),greater<pair<long,pair<int,int>>);
  
  long sum = 0;
  
  for(auto itr = score.begin(),count = 0; count<20; itr++ ){
    if(person[*itr.second.first]==0&&pos[*itr.second.second]==0){
      person[*itr.second.first]=1;
      pos[*itr.second.second]=1;
      sum+=*itr.first;
      count++;
    }
  }
  cout << sum << endl;
  return 0; 
}
