def cal_abs(n, sigma_list): 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]) return abs_val def main(): n = int(input()) sigma_list = list(map(int, input().split())) answer = cal_abs(n, sigma_list) print(answer) if __name__ == "__main__": main()