n = int(input()) a = list(map(int,input().split())) s = 0 for i,u in enumerate(a): for j,v in enumerate(a): s += abs(i-j)*abs(u-v) print(s)