N, s = [input() for _ in range(2)] s_sp = s.split() kai = 0 for i in range(int(N)): for j in range(int(N)): lef = i-j rig = int(s_sp[i])-int(s_sp[j]) kai += lef*rig print(kai)