def main(): n = int(input()) sigma_list = list(map(int, input().split())) abs_val = 0 for i in range(n): for j in range(n): abs_val += abs(i - j) * abs(sigma_list[i] - sigma_list[j]) print(abs_val) if __name__ == "__main__": main()