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