#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int r[100000000];
int main() {
  int n, count = 0, p;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    v.push_back(p);
    r[v[i]] = i;
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < n; i++) {
    count = count + v[i] * abs(r[v[i]] - i);
  }
  cout << count << endl;
  return 0;
}
