n=int(input()) a=list(map(int,input().split())) a=[0]+a ans=0 for i in range(1,n+1): for j in range(1,n+1): ans+=abs(i-j)*abs(a[i]-a[j]) print(ans)