#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int, int> > qu2;
priority_queue<int> pq;
static const int NIL = -1;
static const int INF = 1000000007;
deque<int> deq;
const ll MOD = (1e+9) + 7;
bool chmx(int &a, int b) {
  if (b > a) {
    a = b;
    return true;
  }
  return false;
}
bool chmn(int &a, int b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
int A[2005];
int B[2005];
bool check(int k) {
  int p = B[k];
  int q = B[k + 1];
  if (A[p] * abs(k - p) + A[q] * abs(k + 1 - q) <
      A[p] * abs(k + 1 - p) + A[q] * abs(k - q)) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    A[i] = a;
  }
  for (int i = 0; i < (int)(n); i++) {
    B[i] = i;
  }
  ll ans = 0;
  for (int i = 0; i < (int)(n - 1); i++) {
    for (int j = i; j < n - 1; j++) {
      if (B[j]) {
        swap(B[j], B[j + 1]);
      }
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    ans += A[B[i]] * abs(B[i] - i);
  }
  cout << ans << endl;
  return 0;
}
