n,*a=list(map(int,open(0).read().split())) print(sum(sum((i-j)*abs(a[j]-a[i])for j in range(i))for i in range(n))*2)