/* i dont know anything about scanf and printf pls tell me why i m wrong??*/
#include<stdio.h>
#include
using namespace std;
int main()
{
long n,i,j;
scanf("%l",&n);
long long sum=0;
vector s(n);
for(i=0;i<n;i++)
scanf("%ll",&s[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(s[i]>s[j])
sum+=s[i]-s[j];
else
sum+=s[j]-s[i];
}
}
printf("%ll",sum);
}