#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main() {
  lli n,a,maxval,uniques,ctr = 0;
  vector<lli> v;
  cin >> n;
  for (lli i = 0; i < n; i++)
  {
    cin >> a;
    v.push_back(a);
  }
  uniques = set<lli>(v.begin(),v.end()).size();
  while (uniques > 1)
  {
    maxval = *max_element(v.begin(),v.end());
    auto maxidx = find(v.begin(),v.end(),maxval);
    ctr += (maxval * distance(maxidx,v.end())) - accumulate(maxidx,v.end(),0);
    v.erase(maxidx,v.end());
    uniques = set<lli>(v.begin(),v.end()).size();
  }
  cout << ctr;
  return 0;